PDA

View Full Version : Highlighting particular cells



Lartk
10-17-2012, 11:30 AM
I am trying to highlight particular cells that have the text "1" but this code is not working...

Sub testing()
With ActiveSheet

lastrow = .Cells(.Rows.Count, "A").End(xlUp).Offset(1000, 0).Row
For i = 4 To lastrow

If .Cells(i, "B").Value = "1" Then

Range.Cells(i, "B").Select

With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 65535
.TintAndShade = 0
.PatternTintAndShade = 0
End If
Next i
End With

End Sub

Lartk
10-17-2012, 01:42 PM
I figured it out...

Sub testing()

Dim lastrow As Long
Dim i As Long
With ActiveSheet

lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row
For i = 4 To lastrow

If .Cells(i, "B").Value = "1" Then

With .Cells(i, "B").Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 65535
.TintAndShade = 0
.PatternTintAndShade = 0
End With

End If

Next i
End With

End Sub