Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default Stop the loop when found.

I have the below comparison between two columns. Where the cells match, and a
different comparison of an different cell pair on the same row also matches,
it highlights a row and fills in a cell using data from its matching cell. My
problem is that, I want it so that once it's found a match, it should stop
the loop and go on to the next item in the range.

Hope someone can help.

For Each rcellIm In rngIm.Cells
For Each rcellDt In rngDt.Cells
If InStr(1, rcellDt.Value, rcellIm, vbTextCompare) Then
If rcellDt.Offset(0, 2) = rcellIm.Offset(0, 10) Then
rcellDt.Offset(0, 5) = rcellIm.Offset(0, 3)
rcellIm.EntireRow.Interior.ColorIndex = 35
End If
End If
Next rcellDt
Next rcellIm

Thanks
--
H
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 147
Default Stop the loop when found.

Try This:

Stoploop = "No"
For Each rcellIm In rngIm.Cells
For Each rcellDt In rngDt.Cells
If InStr(1, rcellDt.Value, rcellIm, vbTextCompare) Then
If rcellDt.Offset(0, 2) = rcellIm.Offset(0, 10) Then
rcellDt.Offset(0, 5) = rcellIm.Offset(0, 3)
rcellIm.EntireRow.Interior.ColorIndex = 35
Stoploop = "Yes"
Exit For
End If
End If
Next rcellDt
If Stoploop = "Yes" Then
Exit For
End If
Next rcellIm


Jason Zischke



"hfazal" wrote:

I have the below comparison between two columns. Where the cells match, and a
different comparison of an different cell pair on the same row also matches,
it highlights a row and fills in a cell using data from its matching cell. My
problem is that, I want it so that once it's found a match, it should stop
the loop and go on to the next item in the range.

Hope someone can help.

For Each rcellIm In rngIm.Cells
For Each rcellDt In rngDt.Cells
If InStr(1, rcellDt.Value, rcellIm, vbTextCompare) Then
If rcellDt.Offset(0, 2) = rcellIm.Offset(0, 10) Then
rcellDt.Offset(0, 5) = rcellIm.Offset(0, 3)
rcellIm.EntireRow.Interior.ColorIndex = 35
End If
End If
Next rcellDt
Next rcellIm

Thanks
--
H

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
return cells below stop when word found bwilk77 Excel Discussion (Misc queries) 1 April 2nd 09 05:50 PM
Stop a loop when certain data is found jsmith Excel Discussion (Misc queries) 3 June 2nd 08 10:12 PM
End a loop if text is not found Ernesto[_3_] Excel Programming 2 August 19th 05 10:33 PM
Loop to change cell color based on found value? gaba Excel Programming 3 November 3rd 04 02:33 PM
HELP!!!! Can't stop a loop (NOT an infinite loop) TBA[_2_] Excel Programming 3 December 14th 03 03:33 PM


All times are GMT +1. The time now is 01:58 PM.

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

About Us

"It's about Microsoft Excel"