PDA

View Full Version : Random



oleg_v
07-07-2010, 12:48 AM
hi

how can i get random numbers
between 34.01 and 33.99 i need at least 25 numbers


thanks

Aussiebear
07-07-2010, 03:11 AM
lookup RandBetween in Excel Help. This will give you a start until someone comes along.

GTO
07-07-2010, 03:33 AM
Try:

=RAND()*(34.01-33.99)+33.99

...entered as an array.

Good reading: http://www.cpearson.com/excel/randomNumbers.aspx

oleg_v
07-07-2010, 03:34 AM
thanks

oleg_v
07-07-2010, 04:10 AM
hi
i need some help with a macro.
in sheet1 cell b1 the user enters the upper number in cell b2 the user enters the lower number and in cell b3 the user enters the number of how much random numbers needed
the macro that i need for random between two numbers



thanks for the help

GTO
07-07-2010, 05:18 AM
Oleg,

Could you stick with your original thread on this?

Mark

oleg_v
07-07-2010, 05:20 AM
Tell me how and I will do this

mdmackillop
07-07-2010, 08:07 AM
Threads merged.

YasserKhalil
07-07-2010, 10:46 AM
Hi guy
try this !!

mdmackillop
07-07-2010, 11:37 AM
Hi Yasser,
Try to avoid looping, it slows down your code

Sub Test()
Dim rng1, cell, R1, R2 As Range
Dim cel As Range
Set cel = Selection
Set R1 = ActiveSheet.Range("B1")
Set R2 = ActiveSheet.Range("B2")
Set R3 = ActiveSheet.Range("B3")
Set rng1 = Range(Cells(1, "C"), Cells(R3, "C"))
Application.ScreenUpdating = False
Columns("C:C").ClearContents
With rng1
.Formula = "=Randbetween(" & R1 & "," & R2 & ")"
.Copy
.PasteSpecial Paste:=xlPasteValues
End With
cel.Select
Application.CutCopyMode = False
Application.ScreenUpdating = True
End Sub

oleg_v
07-07-2010, 10:02 PM
hi

how can i get it to work?

oleg_v
07-07-2010, 10:24 PM
hi
i can not use numbers with decimal places for example
i need 20 numbers between 34.01 and 33.99

this not working
thanks for your help

mdmackillop
07-07-2010, 11:59 PM
hi
i can not use numbers with decimal places for example
i need 20 numbers between 34.01 and 33.99
There is only one whole number, I believe, between 34.01 and 33.99. Can you post a list which might be randomly generated which meets your criteria?

oleg_v
07-08-2010, 12:05 AM
hi
i column E you can see the results that was generated by the formula:
=RAND()*(34.01-33.99)+33.99

mdmackillop
07-08-2010, 12:09 AM
That is what you asked for in Post 1. What answer are you expecting, as per my last question?

oleg_v
07-08-2010, 12:12 AM
i need a macro to do this.
for the user that will enter the desirable borders and by
pressing the button he will get the results.

thanks

mdmackillop
07-08-2010, 12:18 AM
I cannot assist if you do not answer the questions I have asked.

YasserKhalil
07-08-2010, 01:22 AM
Try this
I think the solution of array formulas is the best
Generally here's the code


Sub Test()
Dim rng1, cell, R1, R2 As Range
Dim cel As Range
Set cel = Selection
Set R1 = ActiveSheet.Range("B1")
Set R2 = ActiveSheet.Range("B2")
Set R3 = ActiveSheet.Range("B3")
Set rng1 = Range(Cells(1, "C"), Cells(R3, "C"))
Application.ScreenUpdating = False
Columns("C:C").ClearContents
With rng1
.Formula = "=RAND()*(" & (R1 - R2) + R2 & ")"
.Copy
.PasteSpecial Paste:=xlPasteValues
End With
cel.Select
Application.CutCopyMode = False
Application.ScreenUpdating = True
End Sub

Bob Phillips
07-08-2010, 04:31 AM
Try



Sub Test()
Dim rng1, cell, R1 As Double, R2 As Double, R3 As Long
R1 = ActiveSheet.Range("B1").Value2
R2 = ActiveSheet.Range("B2").Value2
R3 = ActiveSheet.Range("B3").Value2

Application.ScreenUpdating = False
Columns("C:C").ClearContents
With Range("C1").Resize(R3)

.Formula = "=RAND()*(" & R2 & "-" & R1 & ")+" & R1
.Value = .Value
End With
Application.ScreenUpdating = True
End Sub