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:

Some videos you may like

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,263
Office Version
  1. 365
Platform
  1. Windows
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
 

Bill_Biggs

Well-known Member
Joined
Feb 6, 2007
Messages
1,216
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?
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,263
Office Version
  1. 365
Platform
  1. Windows
Bill

Pretty hard to help without seeing the rest of the code.:)
 

Bill_Biggs

Well-known Member
Joined
Feb 6, 2007
Messages
1,216

ADVERTISEMENT

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:

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
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
 

Bill_Biggs

Well-known Member
Joined
Feb 6, 2007
Messages
1,216
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,126,957
Messages
5,621,827
Members
415,859
Latest member
Vain

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
Top