Only Run part of a DO loop on first instance

mantis_sg

Board Regular
Joined
Nov 16, 2005
Messages
126
Is the there a way to skip some code after the first loop? e.g.

I have a do loop that loops 5 times, I want all the code to be executed during the first loop but for the 2nd,3rd,4th and 5th times I only want a certain ammount of the code to run...?????
 
Greg,

Code:
Sub FooFoo()
    Dim booDoneOnce As Boolean
    
    booDoneOnce = False         ' optional
    Do Until SomeCondition
        ' code
        ' code
        ' more very interesting stuff
        If Not booDoneOnce Then
            ' code that should
            ' only execute the one time
        End If
        booDoneOnce = True
    Loop
End Sub
Worked perfectly, thank you.
 
Upvote 0

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.

Forum statistics

Threads
1,216,444
Messages
6,130,659
Members
449,585
Latest member
Nattarinee

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