QP School
Loop to display numbers in VBA - Printable Version

+- QP School (https://qomplainerzschool.lima-city.de)
+-- Forum: Tutorials (https://qomplainerzschool.lima-city.de/forumdisplay.php?fid=3)
+--- Forum: Excel VBA Tutorials (https://qomplainerzschool.lima-city.de/forumdisplay.php?fid=48)
+--- Thread: Loop to display numbers in VBA (/showthread.php?tid=5236)



Loop to display numbers in VBA - Qomplainerz - 07-27-2023

Description:

This code uses a loop to display numbers from 1 to 5 in separate message boxes.

Example:

Sub DisplayNumbers()
    Dim i As Integer

    For i = 1 To 5
        MsgBox "Number: " & i
    Next i
End Sub

Explanation:

This code defines a subroutine named DisplayNumbers. 
It declares a variable i to use as a loop counter. 
The For loop runs from 1 to 5, and for each iteration, a message box displays the value of i.

The For loop is a control structure used to execute a block of code repeatedly for a specific range of values. 
In this case, the loop runs five times, and the i variable takes values from 1 to 5.