Run-time error '91' Object variable or With block variable not se

B

Ben

Hi all,


This is a repost from last Friday, but not sure why I didn't see my earlier
post in the newsgroup. Here's my question:

I pass to the below routine to an Excel object and want to look for some
value in the cell, but when execution reaches to the find statement, I got an
error:

Run-time error '91'
Object variable or With block variable not set

I looked at the code for quite a while and couldn't see the reason why,
perhaps another set of eyes will see what I am missing. Thanks for your help.

sub Test (ByRef oWkbk As Excel.Workbook)

Dim oWksh As Excel.Worksheet

Set oWksh = oWkbk.ActiveSheet

oWksh.Range("A1").Select
Selection.End(xlDown).Select
dLastRow = oWkbk.Parent.ActiveCell.Row


oWksh.Cells.Find(What:="FindSomething", After:=ActiveCell,
LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate

end sub



Ben




--
 
D

Douglas J Steele

You don't say what line of code it's failing on, but I'd suspect:

Selection.End(xlDown).Select

Access has no idea what Selection is.

I think oWksh.Selection.End(xlDown).Select is what you need.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top