Ad Clicks : Ad Views :
Excel formulas and tutorials

Excel formulas and useful tools

img

Excel macro for loop

/
/
/
152 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 *

It is main inner container footer text