VBA for using Find feature

normpam

Active Member
Joined
Oct 30, 2002
Messages
360
I've written some code that will ask the user for a sheet name; go to the sheet, and find an item. If it finds it, I direct the program to go back to the first sheet and put the word "Match" somewhere. No problem. But, if the item is NOT found, then my code generates an error,

"Object variable or With Block variable not set"

How can I work around this? All I want to do is write my code so that it loops through a list and searches for items on another sheet.

Much Thanks for any help.
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Assign the result of the Find method to a Range object and compare it with Nothing, like this:
Code:
    Dim foundItem As Range
    
    Set foundItem = Cells.Find("xxx")
    
    If Not foundItem Is Nothing Then
        MsgBox "Found it"
    Else
        MsgBox "Didn't find it"
    End If
 
Upvote 0
Thanks. I'm working on trying go figure out if this will work for me. If only I could get an Excel fairy that could touch me with her wand so I'd know every VBA command!
 
Upvote 0

Forum statistics

Threads
1,224,527
Messages
6,179,345
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