You are on page 1of 1

Mark cells with the same value in column A in the B column

This example search in Sheets("Sheet1") in column A for every cell with "ron" and
use Offset to mark the cell in the column to the right. Note: you can add more
values to the array MyArr.

Sub Mark_cells_in_column()
Dim FirstAddress As String
Dim MyArr As Variant
Dim Rng As Range
Dim I As Long

With Application
.ScreenUpdating = False
.EnableEvents = False
End With

'Search for a Value Or Values in a range


'You can also use more values like this Array("ron", "dave")
MyArr = Array("ron")

'Search Column or range


With Sheets("Sheet1").Range("A:A")

'clear the cells in the column to the right


.Offset(0, 1).ClearContents

For I = LBound(MyArr) To UBound(MyArr)

'If you want to find a part of the rng.value then use xlPart
'if you use LookIn:=xlValues it will also work with a
'formula cell that evaluates to "ron"

Set Rng = .Find(What:=MyArr(I), _


After:=.Cells(.Cells.Count), _
LookIn:=xlFormulas, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)

If Not Rng Is Nothing Then


FirstAddress = Rng.Address
Do
'mark the cell in the column to the right if "Ron" is found
Rng.Offset(0, 1).Value = "X"
Set Rng = .FindNext(Rng)
Loop While Not Rng Is Nothing And Rng.Address <> FirstAddress
End If
Next I
End With

With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End Sub

You might also like