ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   macro to set bottom and top values for randbetween (https://www.excelbanter.com/excel-programming/447285-macro-set-bottom-top-values-randbetween.html)

Tonso

macro to set bottom and top values for randbetween
 
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

isabelle

macro to set bottom and top values for randbetween
 
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?

Thanks!

Tonso


Tonso

macro to set bottom and top values for randbetween
 
On Wednesday, October 3, 2012 10:22:17 AM UTC-4, Tonso wrote:
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


isabelle,

Thank you very much!!

tonso

Tonso

macro to set bottom and top values for randbetween
 
On Wednesday, October 3, 2012 10:22:17 AM UTC-4, Tonso wrote:
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


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

Claus Busch

macro to set bottom and top values for randbetween
 
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
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2

isabelle

macro to set bottom and top values for randbetween
 
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.

Thanks,

Tonso


Tonso

macro to set bottom and top values for randbetween
 
On Wednesday, October 3, 2012 10:22:17 AM UTC-4, Tonso wrote:
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


Isabelle, Claus,

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


All times are GMT +1. The time now is 11:44 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com