Private Function IsPrime(ByVal n As Integer) As Boolean Dim pb As Integer pb = n - 1 IsPrime = True For i = 2 To pb If n Mod i = 0 Then IsPrime = False Exit For End If Next iEnd Function