D
Dennis
I found this in the NG archives and use it at work with EXCEL 2000.
Sub Color_cells_in_Range()
Dim FirstAddress As String
Dim myArr As Variant
Dim rng As Range
Dim I As Long
Application.ScreenUpdating = False
myArr = Array("7", "27")
'You can also use more values in the Array
'myArr = Array("ron", "dave")
With Sheets("Sheet1").Range("B1:G500")
.Interior.ColorIndex = xlColorIndexNone
'change the fill color to "no fill" in all cells
For I = LBound(myArr) To UBound(myArr)
Set rng = .Find(What:=myArr(I), _
After:=Range("A1"), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
'if you use LookIn:=xlValues it will also work with a
'a formula cell that evaluates to "ron"
If Not rng Is Nothing Then
FirstAddress = rng.Address
Do
rng.Interior.ColorIndex = 3
'make the cell red
Set rng = .FindNext(rng)
Loop While Not rng Is Nothing And rng.Address <>
FirstAddress
End If
Next I
End With
Application.ScreenUpdating = True
End Sub
At home with 2003 I get a syntax error on "Loop While Not rng Is Nothing And
rng.Address <>"
TIA
Dennis
===========
Sub Color_cells_in_Range()
Dim FirstAddress As String
Dim myArr As Variant
Dim rng As Range
Dim I As Long
Application.ScreenUpdating = False
myArr = Array("7", "27")
'You can also use more values in the Array
'myArr = Array("ron", "dave")
With Sheets("Sheet1").Range("B1:G500")
.Interior.ColorIndex = xlColorIndexNone
'change the fill color to "no fill" in all cells
For I = LBound(myArr) To UBound(myArr)
Set rng = .Find(What:=myArr(I), _
After:=Range("A1"), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
'if you use LookIn:=xlValues it will also work with a
'a formula cell that evaluates to "ron"
If Not rng Is Nothing Then
FirstAddress = rng.Address
Do
rng.Interior.ColorIndex = 3
'make the cell red
Set rng = .FindNext(rng)
Loop While Not rng Is Nothing And rng.Address <>
FirstAddress
End If
Next I
End With
Application.ScreenUpdating = True
End Sub
At home with 2003 I get a syntax error on "Loop While Not rng Is Nothing And
rng.Address <>"
TIA
Dennis
===========