Search column & then interior colour of cell Red

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
3,914
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
 

Some videos you may like

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.

JoeMo

MrExcel MVP
Joined
May 26, 2009
Messages
17,414
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
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
 

Watch MrExcel Video

Forum statistics

Threads
1,128,057
Messages
5,628,354
Members
416,313
Latest member
Dan99321

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
Top