Private Sub CommandButton1_Click()
Dim cell As Range, i As Long, r As Long
If Application.CountA(Range("C3:C5")) = 3 Then
With Sheets("Data").Range("A1").CurrentRegion
.AutoFilter 4, Range("C3").Value
.AutoFilter 5, Range("C4").Value
.AutoFilter 6, Range("C5").Value
With .Columns(6).SpecialCells(xlCellTypeVisible)
If .Count > 1 Then
r = Int((.Count - 2 + 1) * Rnd + 2)
For Each cell In .Cells
i = i + 1
If i = r Then
If cell = "Male" Then cell = "Female" Else cell = "Male"
MsgBox "Row " & cell.Row & " changed.", vbInformation, "Gender Change"
Exit For
End If
Next
Else
MsgBox "No rows match the selected Grade/Discipline/Gender", , ""
End If
End With
.Parent.AutoFilterMode = False
End With
Else
MsgBox "Missing Entry.", vbExclamation, "Grade Discipline Gender"
End If
End Sub
Bookmarks