Max and mslabbe,
I think I am in a better mood now. <g>
Here is something that provides a list of 10 consecutive winners in Column B.
(I hope)
The next ten (if run) would go directly underneath the previous ten.
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
Function TipTheScales_R2(ByRef rng As Excel.Range) As Variant
'Jim Cone - San Francisco, USA - January 02, 2007
'Called by sub PickWinner_R2
On Error GoTo OverWeight_Err
Dim varArr() As Variant
Dim N As Long
Dim i As Long
Dim j As Long
Dim lngValue As Long
Dim lngPortion As Long
ReDim varArr(1 To 100, 1 To 2)
For N = 1 To rng.Count
lngValue = rng(N).Value
lngPortion = Int(lngValue)
For i = 1 To lngPortion
varArr(j + i, 1) = lngValue
varArr(j + i, 2) = rng(N).Offset(-1, 0).Value
Next
j = j + lngPortion
Application.StatusBar = " WORKING " & Format$(N / rng.Count, "#00%")
Next
'Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
Randomize
N = Int(100 * Rnd) + 1
Application.Calculation = xlCalculationAutomatic
TipTheScales_R2 = varArr(N, 2)
Erase varArr
' Set rng = Nothing
Exit Function
OverWeight_Err:
Beep
TipTheScales_R2 = "Error " & Err.Number & " - " & Err.Description
End Function
Sub PickWinner_R2()
'Picks a random value using weighted percent values in the selection.
'Percent values should be entered as a whole number in a single row.
'Return value is the cell text directly above the chosen percent value.
'Calls function TipTheScales.
'Returns 10 consecutive picks in column B.
'Jim Cone - San Francisco, USA - January 02, 2007
'---
Dim Rw As Long
Dim N As Long
Dim varSum As Variant
Dim rngNums As Excel.Range
Set rngNums = Selection
varSum = Application.Sum(rngNums)
If IsError(varSum) Then
MsgBox "Sections values must total 100. "
Exit Sub
ElseIf varSum <> 100 Then
MsgBox "Selection values must total 100. "
Exit Sub
ElseIf Selection.Rows.Count <> 1 Then
MsgBox "Select only one row. "
Exit Sub
Else
For N = 1 To rngNums.Count
If Not IsNumeric(rngNums(N)) Or Len(rngNums(N)) = 0 Then
MsgBox "All entries in the rngnums must be numbers. "
Exit Sub
End If
Next
End If
Application.Calculation = xlCalculationManual
Rw = Cells(Rows.Count, 2).End(xlUp)(2, 1).Row
For N = Rw To Rw + 9
Cells(N, 2).Value = TipTheScales_R2(rngNums)
Next
Application.Calculation = xlCalculationAutomatic
Application.StatusBar = False
Set rngNums = Nothing
End Sub
'------------
"Jim Cone" <
[email protected]>
wrote in message
Hi Max,
Besides making the spelling error, I think I created a pile of crap.
If the percentages total 100 then you don't need the LCM.
If they don't total 100 then it becomes a guess as to how
to distribute the weightings.
Do you recall "Springtime for Hitler", where the "producers" sold
multiple 50% shares of the production to gullible old people?
I am sure I was involved in that somewhere.
Regards,
Jim Cone
"Max" <
[email protected]>
wrote in message
Hi Jim,
Happy New Year !
In VBE Tools > References,
I checked: atpvbaen.xls instead
(could not find ATPVBAIN.XLA)
But think I got your sub running well
How could your Sub WhoIsIt() be tweaked to write the results of say, 10 runs
into a col range instead ? Thanks.