Find the next Cell with interior color using Do Until...Loop

R

RyanH

I need a macro to scan down Col. B from the ActiveCell to find the next cell
that is hightlighted orange ( .Interior.ColorIndex = 40). Here is what I
got, but it does not seem to work.

Sub FindLastRow()

Dim LastRow As Long
Dim i As Long

Do
For i = ActiveCell.Row To ActiveCell.Row + 30
LastRow = Cells(i, 2).Row
Next i
Loop Until Cells(i, 2).Interior.ColorIndex = 40

MsgBox "LastRow = " & LastRow

End Sub

Thanks in Advance,
Ryan
 
G

Gary''s Student

Sub ryan()
Set r = Range(ActiveCell.Address & ":B65536")
For Each rr In r
If rr.Interior.ColorIndex = 40 Then
MsgBox (rr.Row)
Exit Sub
End If
Next
End Sub
 
M

Mike H

Possible

Sub FindLastRow()
Dim LastRow As Long
Dim i As Long
For i = ActiveCell.Row To 65536
If Cells(i, 2).Interior.ColorIndex = 40 Then
MsgBox Cells(i, 2).Address
Exit Sub
End If
Next
End Sub

Mike
 
R

RyanH

Thanks for the responses. I failed to mention that this macro is actually
only a small part of a larger macro. I need to only exit the loop, not exit
the sub. Is this possible?

Thanks
Ryan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top