Hello,
I have an issue, I need to:
I performed this:
Option Explicit
Sub randomNumbersStandard()
Dim highestValue As Double
Dim lowestValue As Double
Dim columnsInput As Double
Dim rowsInput As Double
Dim cell As Range
Dim rng As Range
highestValue = InputBox("Please enter the highest number of all possible random variable", "Highest Random Number")
lowestValue = InputBox("Please enter the lowest number of all possible random variable", "Lowest Random Variable ")
columnsInput = InputBox("Specify how many columns you want to create", " Columns")
rowsInput = InputBox("Specify how many rows you want to create", " Rows")
Sheets.Add.Name = "Random Numbers"
Set rng = Selection(rowsInput, columnsInput)
For Each cell In rng
cell.Value = WorksheetFunction.RandBetween(lowestValue, highestValue)
Next
End Sub
In this way it only enters a random number in one cell, but I need in a range (from input rows and columns). Could someone give me a hint how can I do this without using selection, because if it askes me to introduce the rows and columns it means that i cannot select the area.
I am not sure if I understood the assignment.
Thank you in advance!
I have an issue, I need to:
- Ask the user for the highest and lowest possible values of the random numbers
- Ask the user how many rows and how many columns she/he wants to create
- Insert a new sheet into the workbook with the name "‘RandomNumbers"’ and fill this sheet with the appropriate amount of randomly created values. Start in cell A1.
I performed this:
Option Explicit
Sub randomNumbersStandard()
Dim highestValue As Double
Dim lowestValue As Double
Dim columnsInput As Double
Dim rowsInput As Double
Dim cell As Range
Dim rng As Range
highestValue = InputBox("Please enter the highest number of all possible random variable", "Highest Random Number")
lowestValue = InputBox("Please enter the lowest number of all possible random variable", "Lowest Random Variable ")
columnsInput = InputBox("Specify how many columns you want to create", " Columns")
rowsInput = InputBox("Specify how many rows you want to create", " Rows")
Sheets.Add.Name = "Random Numbers"
Set rng = Selection(rowsInput, columnsInput)
For Each cell In rng
cell.Value = WorksheetFunction.RandBetween(lowestValue, highestValue)
Next
End Sub
In this way it only enters a random number in one cell, but I need in a range (from input rows and columns). Could someone give me a hint how can I do this without using selection, because if it askes me to introduce the rows and columns it means that i cannot select the area.
I am not sure if I understood the assignment.
Thank you in advance!