This example works but I hope there is a shorter way of writing it.
Is there?
Thank you
This example works but I hope there is a shorter way of writing it.
Is there?
Thank you
Thank you for your help
What exactly do you want this to do?
DO you want the random number (spins) to populate the cells in Column 1 for 48 rows?
I am not sure what the code is intended to do, otherwise I could probably help.
If you have posted the same question at multiple forums, please read this IMPORTANT INFO.
Please use the thread tools to mark your thread Solved
Please review the Knowledge Base
for samples and solutions , or to submit your own!
[VBA]Sub spin()
Application.ScreenUpdating = False
Dim a As Variant, b As Integer, k As Single, j As Long, i As Long
a = Array("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", _
"11", "12", "13", "14", "15", "16", "17", "18", "19", "20", _
"21", "22", "23", "24", "25", "26", "27", "28", "29", "30", _
"31", "32", "33", "34", "35", "36", "37", "38", "39", _
"40", "41", "42", "43", "44", "45", "46", "47", "48", "49")
spins = 200
For i = 1 To spins
b = Rnd() * 49
If b > 48 Then b = 0
[D1].Value = a(b)
k = 0
'For j = 1 To 5000000 / (spins + 1 - i) ' less wait on the first spin
'Next j
Next i
Application.ScreenUpdating = True
End Sub[/VBA]
This works pretty fast for me...not sure what you are looking for. The j loop slows it down..
If you have posted the same question at multiple forums, please read this IMPORTANT INFO.
Please use the thread tools to mark your thread Solved
Please review the Knowledge Base
for samples and solutions , or to submit your own!
Thank you XLGibbs.
I do not want the code to do ANYTHING but spin randomly from 1 to 49 one hundred times and stop.
This is just to give an optical illusion .... at the end of the run the code will pick up a value from a different range and paste it in the same cell the numbers have been spining
Hope I explained it well
Thanks again
Sorry forgot the attachment (revised)
Thank you for your help
Sorry I did not explained it well ... it's the range that I want to write differently if possible
kind of like (Range(A1:A10) no need here to write Range(A1,A2,A3,A4 etc... ) is there a similar way in an array ? (if that is what it's call in this example)
[VBA] "11", "12", "13", "14", "15", "16",[/VBA]
Thank you for your help
You mean to generate a random number between 1 and 49 - repeat this 100 times then stop?[VBA]Originally Posted by ndendrinos
Sub spin()
Dim N As Long
For N = 1 To 100
Randomize
[D1] = Int(Rnd() * 49 + 1)
Next
End Sub
[/VBA]
You know you're really in trouble when the light at the end of the tunnel turns out to be the headlight of a train hurtling towards you
The major part of getting the right answer lies in asking the right question...
Made your code more readable, use VBA tags (this automatically inserts [vba] at the start of your code, and [/vba ] at the end of your code) | Help those helping you by marking your thread solved when it is.
Thank you both very much ... John your code is exactly what I was looking for .Much shorter... took it up to 1000 and I now get the visual I need.
Thank you for your help