VBA search help

rockchalk33

Board Regular
Joined
Jan 12, 2016
Messages
111
Hey all,

I have a Column A with multiple different names for trucks, for example "Shop"....What is wrong with my code below? I am visually seeing the truck labeled "Shop" in column A of Sheet11 but my message box continues to show that it does not exist...Can someone please help me.

Code:
Sub test2()


    Dim Truck_Name As Range
    Dim Search_Range As Range
    Set Search_Range = Sheet11.Range("A:A")
    Set Truck_Name = Search_Range.Find(What:="Shop", MatchCase:=True, LookAt:=xlWhole, searchdirection:=xlPrevious)
    
If Truck_Name Is Nothing Then
MsgBox ("This truck does not exist and must be entered as a new truck first")
Exit Sub
End If


End Sub
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Change your line of code
Code:
Set Search_Range = Sheets("Sheet11").Range("A:A")

Secondly, you have no else statement to tell Excel what to do if "Shop" is found.  Perhaps after the Exit Sub line you add

[CODE]Else: MsgBox ("Shop Found")
or some other action.
 
Last edited:
Upvote 0
Change your line of code
Code:
Set Search_Range = Sheets("Sheet11").Range("A:A")

Secondly, you have no else statement to tell Excel what to do if "Shop" is found.  Perhaps after the Exit Sub line you add

[CODE]Else: MsgBox ("Shop Found")
or some other action.

Awesome! That worked!
 
Upvote 0

Forum statistics

Threads
1,214,918
Messages
6,122,257
Members
449,075
Latest member
staticfluids

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