Search column & then interior colour of cell Red

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,199
Office Version
  1. 2007
Platform
  1. Windows
Evening,

Is there a simple basic code which will change the color of multiple cells from a value entered in search field.

Like this really i suppose.
Type a name in a textbox.
Press the command button.
The code will seach all the cells in column Z1 & down the page looking for the textbox value.
When the code finds a match then each interior cell color is to be changed RED

Thanks
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
You can assign this to a command button:
VBA Code:
Sub HighlightName()
Dim Nm As Variant, Fnd As Range, fAdr As String
Nm = InputBox("Enter name")
If Nm = "" Then Exit Sub
With Range("Z:Z")
    .Cells.Interior.Color = xlNone
    Set Fnd = .Find(Nm, LookIn:=xlValues, lookat:=xlWhole, MatchCase:=False)
    If Not Fnd Is Nothing Then
        fAdr = Fnd.Address
        Fnd.Interior.Color = vbRed
    Else
        MsgBox "Name not found in column Z"
        Exit Sub
    End If
    Do
            Set Fnd = .FindNext(Fnd)
            If Fnd Is Nothing Then Exit Do
            If Fnd.Address = fAdr Then Exit Do
            Fnd.Interior.Color = vbRed
    Loop
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,213,527
Messages
6,114,148
Members
448,552
Latest member
WORKINGWITHNOLEADER

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