macro to set bottom and top values for randbetween

T

Tonso

I want to select a cell or a range of cells, then fill it with randbetween numbers. The bottom and top values will vary from time to time. How can I accomplish this. Maybe have an input box appear where the user could enter the bottom/top values, or designate 2 cells where the user could input the values, invoke the macro, and have it refer to those 2 cells to get the bottom/top values?

Thanks!

Tonso
 
I

isabelle

hi Tonso,

i suppose the values are in range("A1") and range("B1")

x = Evaluate("randbetween(" & [A1] & "," & [B1] & ")")

--
isabelle



Le 2012-10-03 10:22, Tonso a écrit :
I want to select a cell or a range of cells, then fill it with randbetween numbers.

The bottom and top values will vary from time to time. How can I accomplish this.

Maybe have an input box appear where the user could enter the bottom/top values, or

designate 2 cells where the user could input the values, invoke the macro, and have it refer to those 2 cells to get the bottom/top values?
 
T

Tonso

I want to select a cell or a range of cells, then fill it with randbetween numbers. The bottom and top values will vary from time to time. How can Iaccomplish this. Maybe have an input box appear where the user could enterthe bottom/top values, or designate 2 cells where the user could input thevalues, invoke the macro, and have it refer to those 2 cells to get the bottom/top values? Thanks! Tonso

isabelle,

Thank you very much!!

tonso
 
T

Tonso

I want to select a cell or a range of cells, then fill it with randbetween numbers. The bottom and top values will vary from time to time. How can Iaccomplish this. Maybe have an input box appear where the user could enterthe bottom/top values, or designate 2 cells where the user could input thevalues, invoke the macro, and have it refer to those 2 cells to get the bottom/top values? Thanks! Tonso

Isabelle,
The macro works great if a single cell is selected. If more than 1 cell is selected, the value in eery cell is the same. I need to have a different value returned for each cell selected, whether it is a singel cell, or serveral or more cells.

Thanks,

Tonso
 
C

Claus Busch

Hi Tonso,

Am Wed, 3 Oct 2012 08:16:55 -0700 (PDT) schrieb Tonso:
The macro works great if a single cell is selected. If more than 1 cell is selected, the value in eery cell is the same. I need to have a different value returned for each cell selected, whether it is a singel cell, or serveral or more cells.

try it with:

Selection.Formula = "=randbetween(" & [A1] & "," & [B1] & ")"


Regards
Claus Busch
 
I

isabelle

two possibilities,

Sub test1()
For Each c In Selection
Range(c.Address) = Evaluate("randbetween(" & [A1] & "," & [B1] & ")")
Next
End Sub

Sub test2()
'version without doubloon
Dim v As Integer, i As Integer
Set dico = CreateObject("Scripting.Dictionary")
Do Until i = [B1] - [A1] + 1
v = Int(([B1] - [A1] + 1) * Rnd() + [A1])
If Not dico.Exists(v) Then
dico.Add v, v
i = i + 1
End If
Loop
[A2].Resize(i) = Application.Transpose(dico.items)
End Sub


--
isabelle


Le 2012-10-03 11:16, Tonso a écrit :
Isabelle,
The macro works great if a single cell is selected.

If more than 1 cell is selected, the value in eery cell is the same.

I need to have a different value returned for each cell selected, whether it is a singel cell, or serveral or more cells.
 
T

Tonso

I want to select a cell or a range of cells, then fill it with randbetween numbers. The bottom and top values will vary from time to time. How can Iaccomplish this. Maybe have an input box appear where the user could enterthe bottom/top values, or designate 2 cells where the user could input thevalues, invoke the macro, and have it refer to those 2 cells to get the bottom/top values? Thanks! Tonso

Isabelle, Claus,

Thank you both so much for your expert help!!
Sincerely,
Tonso
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top