Hi there!
I am using VBA to do the following:
I use it to write the RANDBETWEEN function in, say, cell A1.
I then use the AUTOFILL command to copy the function down to, say, A10.
I then highlight the range A1 through A10 and Copy/Paste the values generated by the Randbetween function copied down to Cell A10 in place.
All works perfectly as long as I enter specific minimum and maximum values in the RANDBETWEEN function.
The code for the first two steps looks like this (ActiveCell = Cell A1):
BUT HERE IS MY PROBLEM:
The figures -5 and 15 in the function varies based on values of other cells and I want to replace the figures in the code above with some sort of code that would reference those varying values. The minimum value (the -5 in the code above) is based on the value in Cell B1, for example, and the maximum value (the 15 in the code above) is based on the value of Cell C1.
I have been trying to use all sorts of things like replacing the -5 in the code above with Range("C1").Value, but I keep getting an "Expected End of Statement" error in VBA.
I then used the following code, but it places a VALUE in Cell A1, which simply repeats that single result of the Randbetween function value when copied down...
This is that code that does not work:
Please, can anyone help me see the light?
Thank you very much!
Harry
I am using VBA to do the following:
I use it to write the RANDBETWEEN function in, say, cell A1.
I then use the AUTOFILL command to copy the function down to, say, A10.
I then highlight the range A1 through A10 and Copy/Paste the values generated by the Randbetween function copied down to Cell A10 in place.
All works perfectly as long as I enter specific minimum and maximum values in the RANDBETWEEN function.
The code for the first two steps looks like this (ActiveCell = Cell A1):
Code:
ActiveCell.FormulaR1C1 = "=RANDBETWEEN(-5,15)/100"
Selection.Style = "Percent"
Selection.NumberFormat = "0.00%"
Selection.AutoFill Destination:=Range("A1:A10"), Type:=xlFillDefault
BUT HERE IS MY PROBLEM:
The figures -5 and 15 in the function varies based on values of other cells and I want to replace the figures in the code above with some sort of code that would reference those varying values. The minimum value (the -5 in the code above) is based on the value in Cell B1, for example, and the maximum value (the 15 in the code above) is based on the value of Cell C1.
I have been trying to use all sorts of things like replacing the -5 in the code above with Range("C1").Value, but I keep getting an "Expected End of Statement" error in VBA.
I then used the following code, but it places a VALUE in Cell A1, which simply repeats that single result of the Randbetween function value when copied down...
This is that code that does not work:
Code:
ActiveCell.FormulaR1C1 = WorksheetFunction.RandBetween(Range("Bi").Value, Range("C1").Value) / 100
Please, can anyone help me see the light?
Thank you very much!
Harry