This took 56 secs on my machine to go upto 5m numbers
Public Function GetPrimes(inst As Long) As Long
Dim aryPrimes
Dim i As Long
Dim PrimeCount As Long
Dim LastPrime As Long
Dim LastPrimeInst As Long
If inst < 26 Then
aryPrimes = Array(1, 2, 3, 5, 7, 11, 13, 17, 19, 23, _
29, 31, 37, 41, 43, 47, 53, 59, 61, 67, _
71, 73, 79, 89, 97)
GetPrimes = aryPrimes(inst + (LBound(aryPrimes) = 0))
Exit Function
Else
PrimeCount = 25 'ignore prior to 71
For i = 101 To 5000000 Step 2
If IsPrime(i) Then
LastPrime = i
LastPrimeInst = PrimeCount
PrimeCount = PrimeCount + 1
If PrimeCount = inst Then
GetPrimes = i
Exit For
End If
End If
Next i
End If
If GetPrimes = 0 Then Debug.Print LastPrime, LastPrimeInst
End Function
'-----------------------------------------------------------------
Private Function IsPrime(num As Long) As Boolean
'-----------------------------------------------------------------
Dim i As Long
IsPrime = True
If num = 2 Then
IsPrime = True
ElseIf num Mod 2 = 0 Then
IsPrime = False
Else
For i = 3 To num ^ 0.5 Step 2
If num Mod i = 0 Then
IsPrime = False
End If
Next i
End If
End Function
--
---
HTH
Bob
(there's no email, no snail mail, but somewhere should be gmail in my addy)