Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
lastRow=200
For aRow = firstRow to lastRow
If (something) Then //lets say it happened when aRow = 18
aRow=aRow+1 //=> aRow=19
End If
Next aRow //which one ? will next aRow be 19 or 20?
And I increment a aRow variable inside the loop. Would it result in that variable being incremented twice as much?
If you'll debug your code you can see the value yourself. Below code results in
Sub Demo()
Dim firstRow As Integer
Dim lastRow As Integer
Dim aRow As Integer
firstRow = 5
lastRow = 200
For aRow = firstRow To lastRow
If aRow = 7 Then
aRow = aRow + 1
End If
Debug.Print aRow
Next aRow
End Sub
output as
Here, aRow = aRow + 1
increments the value of aRow
by 1
and is subsequently reflected in loop.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.