lezawang
Well-known Member
- Joined
- Mar 27, 2016
- Messages
- 1,805
- Office Version
- 2016
- Platform
- Windows
Hi
The code below is going to fill a range with random number but all the cells will get the same number. What I want, is to fill cells of that range with different random number. So I am thinking to put that line of code in a loop but how can I loop when user might enter any different range? How you would do that please. Thank you very much.
The code below is going to fill a range with random number but all the cells will get the same number. What I want, is to fill cells of that range with different random number. So I am thinking to put that line of code in a loop but how can I loop when user might enter any different range? How you would do that please. Thank you very much.
Code:
Sub cells_fill()
Dim x as integer
Dim y As Integer
Dim n As Integer
Dim m As Integer
x = InputBox("row1")
y = InputBox("col1")
n = InputBox("row2")
m = InputBox("col2")
Range(Cells(x, y), Cells(n, m)).Value = WorksheetFunction.RandBetween(1, 100)
End Sub