Hi All,
Does anyone know if it's possible to show Random Numbers Looping on a UserForm.
I'd like to show random numbers being generated using a Do Loop on a userform.
is this possible?
Thanks,
Jim
Printable View
Hi All,
Does anyone know if it's possible to show Random Numbers Looping on a UserForm.
I'd like to show random numbers being generated using a Do Loop on a userform.
is this possible?
Thanks,
Jim
It's possible
This is in standard module, and there's a command button on the user form to stop it (attachment)
You'll need to integrate into your code of course
Code:Option Explicit
Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Public StopRand As Boolean
Sub StartRand()
Dim R As Double
StopRand = False
Load UserForm1
UserForm1.Show vbModeless
R = Rnd
Do
UserForm1.Label1.Caption = Format(R, "0.000000")
UserForm1.Repaint
DoEvents
R = Rnd
Sleep 500
Loop Until StopRand
UserForm1.Hide
Unload UserForm1
End Sub
Hi Paul,
Thank you. :)
This is exactly what I was looking for.
One last question. Is it possible to update a graph (in the userform beside these random numbers). Can a graph (i.e. histogram) dynamically change or update based on these random numbers all within the same userform?
Thanks,
Jim
Don't think so unless you updated the graph on a sheet, saved it as a picture, and then updated the image on the user form .... maybeQuote:
Is it possible to update a graph (in the userform beside these random numbers). Can a graph (i.e. histogram) dynamically change or update based on these random numbers all within the same userform?
You can fake a Graph with tall, Skinny Labels (Vertical Bars)
Place them in a Frame for easier math
Each Chart Bar (Label) Height would be set by its Random Number and its Top Property would then be Frame Height - Bar Height
For horizontal Bars, it's easier then that. All Lefts are fixed and Bar Widths are a function of the Random Numbers.
Thanks Paul and Sam.
That would be very cool to do but it's beyond my expertise a little. The random numbers looping on the userform will work for now. I guess I can show the same random numbers on a sheet and show the dynamic graph update with each random change.
Thanks again.
I would be no where without this help. Thx.
Jim
Paul's Form with Fake Graph
Thanks Sam. This is neat.
I was successful modifying the userform to add more labels and bars. But I wasn't able to make the bars go up and done (versus side to side).
Lets say I wanted to make the bars go up and down and make the chart look like a bell curve....so that the bars lengths would have a maximum (shaped like a bell curve), with the random number labels looping underneath each bar.
Could you help show that? I was having difficultly getting the bars to move up and down.
Thanks,
Jim
Bell Curve with random values? That ain't gonna happen in this world.
Place the Bars labels in a Frame. Under the Frame, organize the values Labels.
Add this line to the beginning of the StartRandom subUnder the With UserForm1 line, addCode:Dim MaxHeight as Double
Inside the For Each loop, replace .Controls("Bar" & i).Width = 100*R withCode:MaxHeight = .Controls("Frame1").Height
Note that I did not redownload the workbook, so I am working from memory.Code:
With .Controls("Bar" & i)
.Height = R * MaxHeight
.Top = MaxHeight - (1 - R)
End with
Try this version
Attachment 21775
You'll have to play with the sizes to get the legibility you want
This is really really cool. Thanks Paul :)