lezawang
Well-known Member
- Joined
- Mar 27, 2016
- Messages
- 1,805
- Office Version
- 2016
- Platform
- Windows
Hi
I do not understand the for loop below. When I say
That is to me, I am assigning I to 1 and there will be no loop. I did step through but still can not see how "i" can be in the loop when it has been assigned to 1 and the max is i (to i). Can the code below be written in simpler coding? Thank you very much.
Source: https://excelchamps.com/blog/useful-macro-codes-for-vba-newcomers/
I do not understand the for loop below. When I say
Code:
for i=1 to i
That is to me, I am assigning I to 1 and there will be no loop. I did step through but still can not see how "i" can be in the loop when it has been assigned to 1 and the max is i (to i). Can the code below be written in simpler coding? Thank you very much.
Code:
Sub AddSerialNumbers()
Dim i As Integer
On Error GoTo Last
i = InputBox("Enter Value", "Enter Serial Numbers")
For i = 1 To i
ActiveCell.Value = i
ActiveCell.Offset(1, 0).Activate
Next i
Last: Exit Sub
End Sub
Source: https://excelchamps.com/blog/useful-macro-codes-for-vba-newcomers/