Option Explicit
Private Function Eratosthenes(ByVal N As Long) As Long()
Dim A() As Long, I As Long, P As Long, J As Long
' reserve enough space for the array
ReDim A(N)
' initialize i
I = 2
' loop from 2 to n and set all items to 1
Do While I < N: A(I) = 1: I = I + 1: Loop
' initialize p and j
P = 2
J = 4
' loop while the starting number fits in the array
Do While J < N
' loop while in the array
Do While J < N
' nullify
A(J) = 0
' keep jumping to every P item
J = J + P
Loop
P = P + 1
' loop until we find a known prime
Do Until A(P) = 1: P = P + 1: Loop
' prepare J for the next loop
J = P * P
Loop
Eratosthenes = A
End Function
Private Sub Form_Load()
Dim Test() As Long, lngA As Long
Test = Eratosthenes(1000)
For lngA = 1 To UBound(Test)
If Test(lngA) = 1 Then Debug.Print lngA
Next lngA
End Sub