PDA

View Full Version : Solved: Pls help clean up code



ndendrinos
11-24-2006, 07:16 PM
This example works but I hope there is a shorter way of writing it.
Is there?

Thank you

XLGibbs
11-24-2006, 07:22 PM
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.

XLGibbs
11-24-2006, 07:31 PM
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


This works pretty fast for me...not sure what you are looking for. The j loop slows it down..

ndendrinos
11-24-2006, 07:32 PM
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)

ndendrinos
11-24-2006, 07:42 PM
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)


"11", "12", "13", "14", "15", "16",

johnske
11-24-2006, 07:47 PM
...I do not want the code to do ANYTHING but spin randomly from 1 to 49 one hundred times and stop...You mean to generate a random number between 1 and 49 - repeat this 100 times then stop?
Sub spin()

Dim N As Long

For N = 1 To 100
Randomize
[D1] = Int(Rnd() * 49 + 1)
Next

End Sub

ndendrinos
11-24-2006, 07:57 PM
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.