Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Object Variable error

I would still use the same code (with the "unload me" line added).

You can't go wrong by qualifying your ranges.

"Patrick C. Simonds" wrote:

No, sorry it is on a UserForm

"Dave Peterson" wrote in message
...
Your commandbutton1 is a commandbutton from the Control toolbox toolbar
placed
on a worksheet, right?

If that's true, then your unqualified ranges (like cells in cells.find)
will
refer to the sheet that owns the code--not necessarily the activesheet.

Option Explicit
Private Sub CommandButton1_Click()
dim FoundCell as range

with ThisWorkbook.Sheets("paratransit names")
set foundcell = .Cells.Find(What:=me.TextBox1.Text, _
After:=.cells(.cells.count), _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False)
end with
if foundcell is nothing then
'what happens
else
application.goto foundcell
end if

End Sub

"Patrick C. Simonds" wrote:

I get the same error msg.

I case it was not clear as to what I am trying to do, I want this code
to
run without actually making the worksheet "paratransit names" active. The
code below does what I need to the extent that it finds the text, but at
the
expense of making the "paratransit names" worksheet active.

Maybe it is not possible to perform this function without making the
worksheet active. If that is the case, I need something to bring me back
to
the cell on the worksheet which was active when the code was initiated.

Private Sub CommandButton1_Click()

ThisWorkbook.Sheets("paratransit names").Activate

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

Unload UserForm1

End Sub


--

Dave Peterson


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Runtime Error '91' Object variable or With block variable not set Alec Coliver Excel Discussion (Misc queries) 2 October 24th 09 02:29 PM
Runtime Error 91 Object variable or With block variable not set. Tim Excel Programming 9 June 5th 08 10:03 PM
Run-Time error '91': Object variable of With block variable not set jammin1911 Excel Programming 3 June 6th 06 06:36 PM
Run-time error '91': "Object variable or With block variable not set Mike[_92_] Excel Programming 2 December 30th 04 10:59 AM
Cells.Find error Object variable or With block variable not set Peter[_21_] Excel Programming 2 May 8th 04 02:15 PM


All times are GMT +1. The time now is 06:37 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"