Hi.
I need some VBA code that will Find and then select a cell that has a value of "SALES" (and ignore cells that contain a string containing the word SALES (not whole), like "SALES REPORT").
I recorded a macro that does it ok, BUT, if it detects a cell that contains a string including the word SALES, like "SALES REPORT", it spits out an error message which I don't understand, even if a different cell contains the "SALES": "Run-time error '91': Object variable or With block variable not set"
This is my code -
Cells.Find(What:="SALES", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate
Scenario #1 -
Cell A1 = [blank]
Cell A2 = 'SALES' <<< ok/no error!
Scenario #2 -
Cell A1 = 'SALES REPORT' <<< causes the error, despite cell A2 meeting the criteria.
Cell A2 = 'SALES'
What i want to know is:
1) what does this error mean?
2) why does the error appear in scenario #2 and not scenario #1?
3) what can I do to make it work? Ideally I would also like it to bring up a message to notify the user if it found a cell containing "SALES", or if it didn't. Nothing should happen in all other cases. So if you could include this in your solution as well, that would be great.
Thanks in advance!
Jason
Still learning!!!
I need some VBA code that will Find and then select a cell that has a value of "SALES" (and ignore cells that contain a string containing the word SALES (not whole), like "SALES REPORT").
I recorded a macro that does it ok, BUT, if it detects a cell that contains a string including the word SALES, like "SALES REPORT", it spits out an error message which I don't understand, even if a different cell contains the "SALES": "Run-time error '91': Object variable or With block variable not set"
This is my code -
Cells.Find(What:="SALES", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate
Scenario #1 -
Cell A1 = [blank]
Cell A2 = 'SALES' <<< ok/no error!
Scenario #2 -
Cell A1 = 'SALES REPORT' <<< causes the error, despite cell A2 meeting the criteria.
Cell A2 = 'SALES'
What i want to know is:
1) what does this error mean?
2) why does the error appear in scenario #2 and not scenario #1?
3) what can I do to make it work? Ideally I would also like it to bring up a message to notify the user if it found a cell containing "SALES", or if it didn't. Nothing should happen in all other cases. So if you could include this in your solution as well, that would be great.
Thanks in advance!
Jason
Still learning!!!
Last edited: