Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 586
Default Find the next Cell with interior color using Do Until...Loop

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Find the next Cell with interior color using Do Until...Loop

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

--
Gary''s Student - gsnu200772
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Find the next Cell with interior color using Do Until...Loop

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

"RyanH" wrote:

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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 586
Default Find the next Cell with interior color using Do Until...Loop

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

"Mike H" wrote:

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

"RyanH" wrote:

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

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Find the next Cell with interior color using Do Until...Loop

For either Mike's code or my code use:
Exit For
in place of:
Exit Sub
--
Gary''s Student - gsnu200772


"RyanH" wrote:

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

"Mike H" wrote:

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

"RyanH" wrote:

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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cell interior color JohnB Excel Discussion (Misc queries) 4 October 12th 06 06:07 PM
Cell background color (interior color) setting not working Martin E. Excel Programming 1 May 21st 06 07:00 PM
Find range by interior color CG Rosén Excel Programming 3 December 10th 03 01:12 AM
Interior Cell color Pellechi Excel Programming 1 September 23rd 03 03:39 PM


All times are GMT +1. The time now is 03:33 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"