HunterN
Active Member
- Joined
- Mar 19, 2002
- Messages
- 479
Hi,
I have the following module that will go through the used range in the worksheet and find each row where the Interior.color is NOT equal to vbWhite and add the following Row name to the value.
I am just wondering if there is a better way to do this?
Thanks,
Nancy
I have the following module that will go through the used range in the worksheet and find each row where the Interior.color is NOT equal to vbWhite and add the following Row name to the value.
Code:
Sub Colored_Cells()
Dim LastRow As Long
Dim myRow As Long
Range("A1").Select
myRow = ActiveCell.row
'Find the last row in the range
Call FindLastRow(passLast)
LastRow = passLast
For myRow = 1 To LastRow
' MsgBox ("this cells color is " & ActiveCell.Interior.color)
If ActiveCell.Interior.color = vbWhite Then
ActiveCell.Offset(1, 0).Select
Else
ActiveCell.Value = "Row number " & myRow
ActiveCell.Offset(1, 0).Select
End If
Next
Range("A1").Select
End Sub
Sub FindLastRow(passLast)
If WorksheetFunction.CountA(Cells) > 0 Then
'Search for any entry, by searching backwards by rows.
LastRow = Cells.Find(What:="*", after:=[A1], _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).row
passLast = LastRow
End If
End Sub
I am just wondering if there is a better way to do this?
Thanks,
Nancy