How can I call a macro which contains a loop but only run one iteration of that loop?

You a looking for something like that?

Option Explicit

Public FromMacro As Boolean 

Sub X()

    FromMacro = True

    Call MacroX

End Sub

Sub MacroX()

    Dim Iteration As Long
    Dim i As Long

    If FromMacro = True Then
        Iteration = 1
        Iteration = 100
    End If

    For i = 1 To Iteration
        MsgBox Iteration
    Next i

    FromMacro = False

End Sub

Browse More Popular Posts

Leave a Comment