Hello,
I cannot understand why does assigning a value to a variable outside a do while loop, specifically the intCol variable in the following example makes such a huge difference:
A simple periodic table as a result
When a value of 1 is assigned to intCol outside of both loops the outcome of my program looks like this
Not to mention when I assign values to the both variables inside the do untill loop, my excel crashes, same thing happens when I put intRow = 1
in the place of intCol (intCol=1 outside and intRow=1 inside the loop).
I'm new to VBA programming and until stumbling upon this particular example I would never have thought that assigning variables in or outside of a loop could have such an impact on the final result. That being said I would very much appreciate anyone explaining me, why does it happen the way it does Thank you in advance!
I cannot understand why does assigning a value to a variable outside a do while loop, specifically the intCol variable in the following example makes such a huge difference:
VBA Code:
Sub LoopExample11()
Dim intRow As Integer
Dim intCol As Integer
intRow = 1
Do Until intRow > 10
intCol = 1
Do
Cells(intRow, intCol) = intCol * intRow
intCol = intCol + 1
Loop Until intCol > 10
intRow = intRow + 1
Loop
End Sub
A simple periodic table as a result
When a value of 1 is assigned to intCol outside of both loops the outcome of my program looks like this
Not to mention when I assign values to the both variables inside the do untill loop, my excel crashes, same thing happens when I put intRow = 1
in the place of intCol (intCol=1 outside and intRow=1 inside the loop).
I'm new to VBA programming and until stumbling upon this particular example I would never have thought that assigning variables in or outside of a loop could have such an impact on the final result. That being said I would very much appreciate anyone explaining me, why does it happen the way it does Thank you in advance!