Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Loop to display numbers in VBA
#1
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.
Also follow me on Youtube for videos about video games:
https://www.youtube.com/channel/UCxfkGVU...2mQ/videos
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Autofill a series of numbers in a column Qomplainerz 0 388 07-27-2023, 11:23 AM
Last Post: Qomplainerz
  Loop through columns and clear contents Qomplainerz 0 395 07-27-2023, 11:21 AM
Last Post: Qomplainerz
  Generate random numbers in VBA Qomplainerz 0 415 07-27-2023, 11:03 AM
Last Post: Qomplainerz
  Loop through worksheets and print their names in the immediate window Qomplainerz 0 406 07-27-2023, 09:42 AM
Last Post: Qomplainerz
  Loop to fill numbers in cells with VBA Qomplainerz 0 379 07-27-2023, 08:16 AM
Last Post: Qomplainerz
  Calculate the average of three numbers in VBA Qomplainerz 0 322 07-27-2023, 07:40 AM
Last Post: Qomplainerz
  Do Until loop in VBA Qomplainerz 0 280 07-26-2023, 08:34 PM
Last Post: Qomplainerz
  Do While loop in VBA Qomplainerz 0 303 07-26-2023, 08:33 PM
Last Post: Qomplainerz
  For...Next loop in VBA Qomplainerz 0 320 07-26-2023, 08:32 PM
Last Post: Qomplainerz
  Floating-point numbers with double precision in VBA Qomplainerz 0 301 07-26-2023, 08:23 PM
Last Post: Qomplainerz

Forum Jump:


Users browsing this thread: 4 Guest(s)