Thread: Highlght rows
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
JE McGimpsey JE McGimpsey is offline
external usenet poster
 
Posts: 4,624
Default Highlght rows

It's probably not working because your comparison looks for text and
your cells contain numbers.

Try:

Dim rCell As Range
For Each rCell In Range("B1:B" & _
Range("B" & Rows.Count).End(xlUp).Row)
With rCell
If IsNumeric(.Value) Then
If .Value = 5 Then
With .EntireRow.Interior
.ColorIndex = 15
.Pattern = xlSolid
End With
End If
End If
End With
Next rCell

Note that there's no need to select anything.


In article ,
Alan M wrote:

I have a column containing a collection of various numbers. I need to use
code to highlight the rows containing the number 5.

I have tried with this but it does not work.

For Each Cell In Columns(2)

If Cell.Value = "5" Then
EntireRow.Select

With Selection.Interior
.ColorIndex = 15
.Pattern = xlSolid
End With
End If

Not sure why....Help please?