Time saving

mole999

Well-known Member
Joined
Oct 23, 2004
Messages
10,524
Office Version
  1. 2019
  2. 2016
  3. 2013
Platform
  1. Windows
I have a long list of check, change/replace items. once the values for N have been found has been updated I want to leave the NEXT loop and restart the search on the next number, and for the life of me I can't find a way that will restart the search with an increment

What did I miss (tried Next N / Goto I different varieties)
Code:
For N = 1 to 500 STEP 1
  With Sheets("Master Streets")
            If .Range("AG" & N) = "" _
                And .Range("S" & N) = "+" Or .Range("S" & N) = "+" Or .Range("S" & N) = "+" _
                Or .Range("S" & N) = "+" Or .Range("S" & N) = "+" _
                Then _
                .Range("U" & N) = "road": _
                .Range("Y" & N) = "postcode": _
                .Range("AG" & N) = "map": _
                .Range("AH" & N) = "E": _
                .Range("AI" & N) = "N": _
                .Range("S" & N) = "final ID"
            DoEvents
[COLOR=#FF0000]Found this one so force the next loop to start rather than test every other With / End With before looping again[/COLOR]
        End With

        
        With Sheets("Master Streets")
            If .Range("AG" & N) = "" _
                And .Range("S" & N) = "+" Or .Range("S" & N) = "+" Or .Range("S" & N) = "+" _
                Or .Range("S" & N) = "+" Or .Range("S" & N) = "+" _
                Then _
                .Range("U" & N) = "road": _
                .Range("Y" & N) = "postcode": _
                .Range("AG" & N) = "map": _
                .Range("AH" & N) = "E": _
                .Range("AI" & N) = "N": _
                .Range("S" & N) = "final ID"
            DoEvents
        End With
Next N
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
You could use GoTo but it's ugly. I usually use a Boolean for stuff like this:

Code:
Dim keepLooking As Boolean


For N = 1 To 500 Step 1
    keepLooking = True
    With Sheets("Master Streets")
        If .Range("AG" & N) = "" _
        And .Range("S" & N) = "+" Or .Range("S" & N) = "+" Or .Range("S" & N) = "+" _
        Or .Range("S" & N) = "+" Or .Range("S" & N) = "+" _
        Then _
            .Range("U" & N) = "road": _
            .Range("Y" & N) = "postcode": _
            .Range("AG" & N) = "map": _
            .Range("AH" & N) = "E": _
            .Range("AI" & N) = "N": _
            .Range("S" & N) = "final ID": _
            keepLooking = False
        DoEvents
    End With


    If keepLooking Then
        With Sheets("Master Streets")
            If .Range("AG" & N) = "" _
                And .Range("S" & N) = "+" Or .Range("S" & N) = "+" Or .Range("S" & N) = "+" _
                Or .Range("S" & N) = "+" Or .Range("S" & N) = "+" _
                Then _
                .Range("U" & N) = "road": _
                .Range("Y" & N) = "postcode": _
                .Range("AG" & N) = "map": _
                .Range("AH" & N) = "E": _
                .Range("AI" & N) = "N": _
                .Range("S" & N) = "final ID"
            DoEvents
            keepLooking = False
        End With
    End If
Next N

WBD
 
Upvote 0
I had played with GoTo. should that drop it down to Next N (I thought I had tried that).

Totally missed the keep looking
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top