Excel macro - for loop increment

32,222

Just do this:

J = J + 1

Simples.

Share:
32,222
CustomX
Author by

CustomX

I'm a Network Engineer ready to help with a decent knowledge of Excel (VBA). I also enjoy gaming and a bit of web development. SOreadytohelp

Updated on December 28, 2020

Comments

  • CustomX
    CustomX over 3 years

    I've looked but can't find a solution.

    How do you increment a variable? Like in any other language you just do ++(variable name) just before the end of the loop. In my example, I'd like to increment J.

    Dim j as integer
    j = 13
    FinalRow = Range("B15").End(xlUp).Row
            For i = 9 To FinalRow
                Range("B" & i).Copy Destination:=Sheets("Design").Range("A" & j)
                J++
            Next i
    

    The code loops from B9-B15 and pastes the information in the Designsheet from A13 and downwards.