Error Despite Error Statement

Bill_Biggs

Well-known Member
Joined
Feb 6, 2007
Messages
1,216
I have the following snippet of code:

<font face=Courier New><SPAN style="color:#00007F">On</SPAN> <SPAN style="color:#00007F">Error</SPAN> <SPAN style="color:#00007F">GoTo</SPAN> Alpha<br>LstRw = Cells.Find(What:=(B), After:=Cells(1, 1), SearchOrder:=xlByRows, SearchDirection:=xlNext).Row<br></FONT>


Now when B is not found, which is supposed to B a common occurence, it is supposed to goto a different section of the macro. Instead, I am getting the error statement "object variable not set." B is a variant and is established early in the macro. Anybody got any ideas?
 
Last edited:

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Bill

If got an idea - don't use On Error or GoTo.

Rich (BB code):
Set Found = Cells.Find(What:=(B), After:=Cells(1, 1), SearchOrder:=xlByRows, SearchDirection:=xlNext)
 
If Not Found Is Nothing Then
  LstRow = Found.Row
  ' rest of code
Else
  MsgBox "B not found."
End If
 
Upvote 0
Its not working. Now if it does not find a term it simply sails through the codes and errs later in the macro. I really need to stick to the "On Error Goto" theme. Also, I need the LstRow to be assigned a value based on find if it is in the search area. With that in mind, can you help me with this?
 
Upvote 0
Bill

Pretty hard to help without seeing the rest of the code.:)
 
Upvote 0
It is spaghetti code and over 50 lines of macro. I know how you feel about spaghetti code. Are you willing to look it over or should I just post again? The suspence is killing me!
 
Last edited:
Upvote 0
Try this, although I don't like GoTos

Code:
Dim Found As Range
Set Found = Cells.Find(What:=(B), After:=Cells(1, 1), SearchOrder:=xlByRows, SearchDirection:=xlNext)
If Found Is Nothing Then GoTo Alpha
LstRw = Found.Row
 
Upvote 0
I know. I don't like them either but once I learned enough VBA to make a living with it, there has been little time to learn more. Thanks for the extra help. Thank you to Norie, it makes sense now.
 
Upvote 0

Forum statistics

Threads
1,214,878
Messages
6,122,062
Members
449,064
Latest member
scottdog129

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top