#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 31
Default 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   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,101
Default 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   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 31
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
variable height variable width stacked bar charts ambthiru Charts and Charting in Excel 3 January 18th 06 11:41 PM
variable in a link where the variable is the name of the sheet darrelly Excel Worksheet Functions 1 October 7th 05 08:24 AM
Sum cells based on a row variable and seperate column variable CheeseHeadTransplant Excel Worksheet Functions 10 September 23rd 05 06:59 PM
object variable or with block variable not set Diego Excel Discussion (Misc queries) 1 August 9th 05 02:46 PM
why is it saying sheetcnt is "variable not defined" how to do a global variable to share over multiple functions in vba for excel? Daniel Excel Worksheet Functions 1 July 9th 05 03:05 AM


All times are GMT +1. The time now is 04:37 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"