In: Computer Science
Review the following code: | |
Sub RunLoop() | |
For n = 1 to 100 | |
ActiveSheet.Range("A" & n).Value = n | |
End Sub |
This is an MS Excel VBA code.
It prints values from 1 to 100 in the row A of an active tab in an excel worksheet.
Incorrect code
Sub RunLoop() | |
For n = 1 to 100 | |
ActiveSheet.Range("A" & n).Value = n | |
End Sub |
Correct code
Sub RunLoop() | |
For n = 1 to 100 | |
ActiveSheet.Range("A" & n).Value = n | |
Next n | |
End Sub |
Statement in red (Next n) was missing.
Snapshot of the code
Snapshot of the output
This will go up until 100.
Let me know if this is clear.