Resume Next statement on IF condition

londolozi

New Member
Joined
Nov 7, 2008
Messages
25
Hi my problem is with nested For and If statements
Code:
For Leg1rns = 2 To Runs1 + 1
NoLeg1 = Data.Cells(Leg1rns, 3).Value

For Leg2rns = 2 To Runs2 + 1
    NoLeg2 = Data.Cells(Leg2rns, 5).Value
        If NoLeg2 = NoLeg1 Then ???? 'Step the For statement count (Leg2rns) if true
        
For Leg3rns = 2 To Runs3 + 1
    NoLeg3 = Data.Cells(Leg3rns, 7).Value
        If NoLeg3 = NoLeg1 Or NoLeg3 = NoLeg2 Then ???? 'Same as Leg2rns

Next Leg3rns
Next Leg2rns
Next Leg1rns
I am trying to test a condition within a For Next loop however the Next loop is also at the end of the testing. Is this achievable?

Any ideas
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
I have tried to understand what it is you are asking but have so far failed I'm afraid - can you explain me fully what it is you want to achieve?
 
Upvote 0
I need and equivalent of "Continue" in VBA

Code:
For a = 1 to 10 
If b = c then Continue For
If b <> c then Goto 10
10: [I]Action[/I]
Next a
 
Upvote 0
Something like this?
Code:
For Leg1rns = 2 To Runs1 + 1
NoLeg1 = Data.Cells(Leg1rns, 3).Value
gobackhere:
    For Leg2rns = 2 To Runs2 + 1
    NoLeg2 = Data.Cells(Leg2rns, 5).Value
        If NoLeg2 = NoLeg1 Then
            Leg2rns = Leg2rns + 1
            GoTo gobackhere
        Else
            For Leg3rns = 2 To Runs3 + 1
            NoLeg3 = Data.Cells(Leg3rns, 7).Value
                If NoLeg3 <> NoLeg1 Or NoLeg3 <> NoLeg2 Then Exit For 'If true it will go back to Leg2rns
            Next Leg3rns
        End If
    Next Leg2rns
Next Leg1rns
 
Upvote 0

Forum statistics

Threads
1,224,559
Messages
6,179,517
Members
452,921
Latest member
BBQKING

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