Ad Clicks :Ad Views : Ad Clicks :Ad Views : Ad Clicks :Ad Views : Ad Clicks :Ad Views :
    Excel formulas and tutorials

    Excel formulas and useful tools

    Home / Excel Macro / Excel macro for loop

    Excel macro for loop

    /
    /
    /
    806 Views

    This is a tutorial for beginners to learn excel macro for loop.

    Loop sequences may be achieved by using a FOR block or a WHILE.

    Macro for loop using FOR

    A FOR block looks like this:

    For i = 1 To 100
        Range(“A” & i) = “Number” & i
    Next i

    Where i is a variable that changes it’s value progressively on each loop. You can use also Next i+1 to change value by 2 units.

    Excel macro for loop using WHILE

    A WHILE sequence looks like this:

    i = 1
    While 1 <= 100
    Range(“A” & i) = “Number” & i
    i = i + 1
    Wend

    First you have to initialize the value of the variable i and then, inside the While block to change the value of it however you need. Please be advised that if you forget to change the value (i=i+1), your code may loop forever and you need to stop it by pressing Ctrl+Pause (Break).

    excel macro for loop

    Enjoy looping in Excel!

     
    • Facebook
    • Twitter
    • Google+
    • Linkedin
    • Pinterest

    Leave a Comment

    Your email address will not be published. Required fields are marked *

    This site uses Akismet to reduce spam. Learn how your comment data is processed.

    This div height required for enabling the sticky sidebar