Column Specific Search

kod2th3e

Board Regular
Joined
Apr 2, 2008
Messages
87
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.


Col ACol BCol C
123951abc
abc456def
951123ghi
def789123

<tbody>
</tbody>
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.
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December

Forum statistics

Threads
1,221,310
Messages
6,159,173
Members
451,543
Latest member
cesymcox

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