07-27-2023, 11:03 AM
Example:
Sub GenerateRandomNumbers()
Dim i As Long
'Generate and place 10 random numbers in column A
For i = 1 To 10
Cells(i, "A").Value = Int((100 * Rnd) + 1)
Next i
End Sub
Explanation:
The code defines a subroutine named GenerateRandomNumbers.
It declares a loop counter i.
The For loop runs from 1 to 10, generating ten random numbers.
Rnd is used to generate a random number between 0 and 1.
(100 * Rnd) generates a random number between 0 and 100,
and Int((100 * Rnd) + 1) generates a random integer between 1 and 100.
The generated random number is placed in column A for each iteration using Cells(i, "A").Value.
Sub GenerateRandomNumbers()
Dim i As Long
'Generate and place 10 random numbers in column A
For i = 1 To 10
Cells(i, "A").Value = Int((100 * Rnd) + 1)
Next i
End Sub
Explanation:
The code defines a subroutine named GenerateRandomNumbers.
It declares a loop counter i.
The For loop runs from 1 to 10, generating ten random numbers.
Rnd is used to generate a random number between 0 and 1.
(100 * Rnd) generates a random number between 0 and 100,
and Int((100 * Rnd) + 1) generates a random integer between 1 and 100.
The generated random number is placed in column A for each iteration using Cells(i, "A").Value.
Also follow me on Youtube for videos about video games:
https://www.youtube.com/channel/UCxfkGVU...2mQ/videos
https://www.youtube.com/channel/UCxfkGVU...2mQ/videos