Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.misc
|
|||
|
|||
Variable not working
Hi all,
I'm sure I've missed something very simple, but I can't get this bit of code to work - the result keeps coming up with #NAME! I have installed the analysis toolpack and RANDBETWEEN works fine as a formula. However, the code works fine if I just have the code enter strInput into a cell - but fails when I enter it into the formula. Sub fred() Dim strInput As String strInput = InputBox("Input Number") Range("I4").Select ActiveCell.FormulaR1C1 = "=RANDBETWEEN(1,strInput)" End Sub Can anyone help? Many thanks in advance Phil |
#2
Posted to microsoft.public.excel.misc
|
|||
|
|||
Variable not working
You nearly had it, try this.
Sub fred() Dim strInput As Integer strInput = InputBox("Input Number") Range("I4").Select ActiveCell.FormulaR1C1 = "=RANDBETWEEN(1," & strInput & ")" End Sub Mike "Phil" wrote: Hi all, I'm sure I've missed something very simple, but I can't get this bit of code to work - the result keeps coming up with #NAME! I have installed the analysis toolpack and RANDBETWEEN works fine as a formula. However, the code works fine if I just have the code enter strInput into a cell - but fails when I enter it into the formula. Sub fred() Dim strInput As String strInput = InputBox("Input Number") Range("I4").Select ActiveCell.FormulaR1C1 = "=RANDBETWEEN(1,strInput)" End Sub Can anyone help? Many thanks in advance Phil |
#3
Posted to microsoft.public.excel.misc
|
|||
|
|||
Variable not working
On 11 Apr, 11:22, Mike wrote:
You nearly had it, try this. Sub fred() Dim strInput As Integer strInput = InputBox("Input Number") Range("I4").Select ActiveCell.FormulaR1C1 = "=RANDBETWEEN(1," & strInput & ")" End Sub Mike "Phil" wrote: Hi all, I'm sure I've missed something very simple, but I can't get this bit of code to work - the result keeps coming up with #NAME! I have installed the analysis toolpack and RANDBETWEEN works fine as a formula. However, the code works fine if I just have the code enter strInput into a cell - but fails when I enter it into the formula. Sub fred() Dim strInput As String strInput = InputBox("Input Number") Range("I4").Select ActiveCell.FormulaR1C1 = "=RANDBETWEEN(1,strInput)" End Sub Can anyone help? Many thanks in advance Phil- Hide quoted text - - Show quoted text - Mike, that's brilliant! Thanks a million BTW - just about to post another one on the same lines, would appreciate your help on that one too! Cheers Phil |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
variable height variable width stacked bar charts | Charts and Charting in Excel | |||
variable in a link where the variable is the name of the sheet | Excel Worksheet Functions | |||
Sum cells based on a row variable and seperate column variable | Excel Worksheet Functions | |||
object variable or with block variable not set | Excel Discussion (Misc queries) | |||
why is it saying sheetcnt is "variable not defined" how to do a global variable to share over multiple functions in vba for excel? | Excel Worksheet Functions |