I previously posted this, but do not get the results I was hoping for with the 'fix', and I have a question about it. Any help is greatly appreciated!
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.
The following response was posted:
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
First of all, when I incorporated this code, though I specifically used and item that was in both sheets, the result was "Didn't find it". So, it doesn't seem to work. Also, what is the ("xxx") mean in the statement 'set foundItem = Cells.Find("xxx")? Are the X's a variable? Does the result have to be three characters?
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.
The following response was posted:
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
First of all, when I incorporated this code, though I specifically used and item that was in both sheets, the result was "Didn't find it". So, it doesn't seem to work. Also, what is the ("xxx") mean in the statement 'set foundItem = Cells.Find("xxx")? Are the X's a variable? Does the result have to be three characters?