Try this:
Sub x()
Dim rInp As Range, rOut As Range, i As Long, nVal As Long, nSize As Long
nSize = 50
Set rOut = Range("E3").Resize(nSize)
Set rInp = Range("H6", Range("H6").End(xlDown)).Resize(, 2)
If WorksheetFunction.Sum(rInp.Columns(2)) <> 100 Then
MsgBox "Must add to 100%"
Exit Sub
End If
Application.ScreenUpdating = False
Columns(5).ClearContents
Randomize
For i = 1 To rInp.Rows.Count - 1
Do While WorksheetFunction.CountIf(rOut, rInp(i, 1)) < nSize * rInp(i, 2) / 100
nVal = Int(Rnd * nSize) + 1
If rOut(nVal) = vbNullString Then rOut(nVal) = rInp(i, 1)
Loop
Next i
rOut.SpecialCells(xlCellTypeBlanks) = rInp(rInp.Rows.Count, 1)
Application.ScreenUpdating = True
End Sub
If you want it to run automatically you need this in the sheet module. This will run whenever anything in col H or I is changed as I don't know how large your range will be. FWIW I think it would be better to stick with a button.
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 8 Or Target.Column = 9 Then x
End Sub
Bookmarks