I am looking to search for a string within a certain column only and activate that cell. If I have the table below, I want to use an input box to acquire a string from the user and search only column B and activate the cell. If the user enters a string that is not found in column B I'd like a message box to pop up saying that that string wasn't found.
[TABLE="class: grid, width: 250, align: center"]
<tbody>[TR]
[TD]Col A[/TD]
[TD]Col B[/TD]
[TD]Col C[/TD]
[/TR]
[TR]
[TD]123[/TD]
[TD]951[/TD]
[TD]abc[/TD]
[/TR]
[TR]
[TD]abc[/TD]
[TD]456[/TD]
[TD]def[/TD]
[/TR]
[TR]
[TD]951[/TD]
[TD]123[/TD]
[TD]ghi[/TD]
[/TR]
[TR]
[TD]def[/TD]
[TD]789[/TD]
[TD]123[/TD]
[/TR]
</tbody>[/TABLE]
So far I have the following code:
Let's say the user types 123 in the input box. When this happens cell A1 gets activated, I want cell B3 to be activated instead. If the user inputted "abc" in the input box I'd like it to kick out the message box located under the skipmessage line. Thanks in advance for your help.
[TABLE="class: grid, width: 250, align: center"]
<tbody>[TR]
[TD]Col A[/TD]
[TD]Col B[/TD]
[TD]Col C[/TD]
[/TR]
[TR]
[TD]123[/TD]
[TD]951[/TD]
[TD]abc[/TD]
[/TR]
[TR]
[TD]abc[/TD]
[TD]456[/TD]
[TD]def[/TD]
[/TR]
[TR]
[TD]951[/TD]
[TD]123[/TD]
[TD]ghi[/TD]
[/TR]
[TR]
[TD]def[/TD]
[TD]789[/TD]
[TD]123[/TD]
[/TR]
</tbody>[/TABLE]
So far I have the following code:
Code:
sub userfind()
dim struserinput as string
on error goto skipmessage
struserinput = InputBox("Please enter the string you would like to find:", "String?") 'gets the user's input to search for
Cells.Find(What:=struserinput, After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlWhole, SearchOrder:=xlByColumns, Search Direction:=xlNext, _
MatchCase:=True, SearchFormat:=False).activate
skipmessage:
MsgBox "The string you entered is not located within column B", vbExclamation, "Error.."
end sub
Let's say the user types 123 in the input box. When this happens cell A1 gets activated, I want cell B3 to be activated instead. If the user inputted "abc" in the input box I'd like it to kick out the message box located under the skipmessage line. Thanks in advance for your help.