+ Reply to Thread
Results 1 to 2 of 2

Stop the loop when found.

  1. #1
    hfazal
    Guest

    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. #2
    Jason Zischke
    Guest

    RE: 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 to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1