I am trying to loop a sub with this code until B9 has a value. And am uncertain what I am doing wrong the sub works until I include the while statement.
Private Sub CommandButton2_Click()
Range("B5:B18").ClearContents
If [D2] = [R15] Then
Do While IsEmpty("B9") = True
Randomname
Loop
End If
Also posting the code for the sub as it is probably relevant. The sub is a random name picker based on code I found and modified to my needs. It compares two ranges and pulls a name from the source range that hasn't already been used, one name at a time.
Sub Randomname()
Dim source, destination As Range
Set source = ActiveSheet.Range("L15:L28")
Set destination = ActiveSheet.Range("B5:B18")
ReDim randoms(1 To source.Rows.Count)
destrow = 0
For i = 1 To destination.Rows.Count
If destination(i) = "" Then: destrow = i: Exit For
Next i
If destrow = 0 Then: MsgBox "no more room in destination range": Exit Sub
For i = 1 To UBound(randoms): randoms(i) = Rnd(): Next i
ipick = 0: tries = 0
Do While ipick = 0 And tries < UBound(randoms)
tries = tries + 1
minrnd = WorksheetFunction.Min(randoms)
For i = 1 To UBound(randoms)
If randoms(i) = minrnd Then
picked_before = False
For j = 1 To destrow - 1
If source(i) = destination(j) Then: picked_before = True: randoms(i) = 2: Exit For
Next j
If Not picked_before Then: ipick = i
Exit For
End If
Next i
Loop
If ipick = 0 Then: MsgBox "no more unique name possible to pick": Exit Sub
destination(destrow) = source(ipick)
End Sub