Search column based on input box entry - all cells

Smiley54665

New Member
Joined
Feb 25, 2014
Messages
3
Hi,
I am fairly comfortable with VBA, but definitely still consider myself a beginner. I need some help with coming up with VBA module to accomplish the following:

I have labeled data columns in A1:F345. I need my users to be able to click on a box to launch the macro and enter a search word into an input box and then the macro search for any/all cells in column F that contains that value. I would want this to find the text in the cell even if the entire contents do not match.

If possible, I would like to avoid the use of the Ctrl + F functionality of excel because it seems to be working only intermittently with my sheet even if conduct the search manually.

I would then like each of the cells that contain that string to change their background color to yellow.

Any help would be greatly appreciated. Thank you!
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Here is some code that will "yellow" cells that contain the entered text. Just run it, and enter the search text.

I'm not sure what
click on a box
means. If it means a button then assign this macro to the button.

To install, copy this to a module.


Code:
Sub FindIt()
    Const tSheet = "Sheet1"
    Const rRng = "A1:F345"
    Const Yellow = 6
    Const NoColor = xlNone
    Dim c, firstaddress, sResp
    
    sResp = InputBox("What are you looking for?", "Finder")
    If sResp = "" Then Exit Sub
    
    With Sheets(tSheet).Range(rRng)
        .Interior.ColorIndex = NoColor
        Set c = .Find(sResp, LookIn:=xlValues)
        If Not c Is Nothing Then
            firstaddress = c.Address
            Do
                c.Interior.ColorIndex = Yellow
                Set c = .FindNext(c)
            Loop While Not c Is Nothing And c.Address <> firstaddress
        End If
    End With
    
End Sub
 
Upvote 0
Yes, by "click on a box", I was referring to assigning a button for the macro. Sorry for the confusion.

This works perfectly! Thank you very much!
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,326
Messages
6,124,267
Members
449,149
Latest member
mwdbActuary

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