View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Peter T Peter T is offline
external usenet poster
 
Posts: 5,600
Default Locate last row containing ColorIndex 35

Sub test2()
Dim nLastURrow As Long
Dim i As Long, n As Long
Dim r As Range, cel As Range
Dim v

Set r = ActiveSheet.UsedRange
nLastURrow = r.Rows.Count
r.Select
For i = nLastURrow To 1 Step -1
v = r.Rows(i).Interior.ColorIndex
If IsNull(v) Then
For Each cel In r.Rows(i).Cells
If cel.Interior.ColorIndex = 35 Then
n = r.Rows(i).Row
Exit For
End If
Next
ElseIf v = 35 Then
n = r.Rows(i).Row
End If
If n Then Exit For
Next

MsgBox n ' if 0 failed to find #35

End Sub

Note - entire rows of the same format can exist outside the used range,
perhaps with #35 ?. As written this only tests within the used range.

Regards,
Peter T

"XP" wrote in message
...
I am using Office 2003 on Windows XP.

I need to find the bottom-most row in a sheet - any column - that contains
an interior color index of 35. Is a "For Each" over all cells the

only/best
way?

Could someone please post example code?
Thanks much in advance