DT POR Macro

kool_jaysmiles

New Member
Joined
Aug 11, 2011
Messages
2
I have created a macro which is to find an excat match in the column. It works for other seasons except fall. Can you please help. This is the error message that I get."Object Variable or with block variable not set”. The debugger shows the error here:

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


I tried changing (LookAt_:=xlPart ) the part to whole, but does not work. I can send over the sheets if someone can help.
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Please run the macro in Break mode and see which column it selects when the Macro Finds for the value "B".
 
Upvote 0
This is the error message that I get."Object Variable or with block variable not set”. The debugger shows the error here:

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

I tried changing (LookAt_:=xlPart ) the part to whole, but does not work. I can send over the sheets if someone can help.
This error means you need an object variable against this statement which VBA expects it to be there but does not find it. In your case, the object is range. So you have approach this as like:
Code:
[FONT=Calibri][COLOR=black]Dim r as Range[/COLOR][/FONT]
[FONT=Calibri]Set r = [/FONT][COLOR=#1f497d][FONT=Calibri][COLOR=red]Selection[/COLOR].Find(What:="B", After:=ActiveCell, LookIn:=xlFormulas, LookAt _[/FONT][/COLOR]
[FONT=Calibri][COLOR=#1f497d]:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=_[/COLOR][/FONT]
[FONT=Calibri][COLOR=#1f497d]False, SearchFormat:=False)[/COLOR][/FONT]
Don't use Select, Selection and Activate while using macros. They come in due to macro recorder.
 
Upvote 0
If you are using the above mention code then this code will also help when you don't find B

Code:
If r Is Nothing Then Goto Somewhere:

Where Somwhere: is the place where the macro should proceed if B is not found. or just put 'Exit Sub' if you want exit macro if B is not found.
 
Upvote 0

Forum statistics

Threads
1,224,527
Messages
6,179,351
Members
452,907
Latest member
Roland Deschain

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