View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
isabelle isabelle is offline
external usenet poster
 
Posts: 587
Default 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