I have referred to the above code for modifications as follows.
Sub wikipedia_primes_translated1()
Dim n As Long
n = Application.InputBox("Input prime range", "Input prompt", 1, Type:=1)
ReDim b(2 To n) As Boolean
Dim a#(), i&, j&, r&, c&, c1&, c2&, c3&
Dim start#
ReDim a(1 To n / (Log(n) - 2), 1 To 4)
Range(Range("B2"), Range("B2").End(xlDown)).Resize(, 4).Clear
Range("G1") = n
r = 1048000 ' max display rows per array
start = Timer
For i = 2 To Int(n ^ 0.5)
If b(i) = False Then
For j = i ^ 2 To n Step i
b(j) = True
Next j
End If
Next i
For i = 2 To n
If b(i) = False Then
c = c + 1
Select Case c
Case 1 To r
a(c, 1) = i
Case r + 1 To 2 * r
c1 = c - r
a(c1, 2) = i
Case 2 * r + 1 To 3 * r
c2 = c - 2 * r
a(c2, 3) = i
Case Else
c3 = c - 3 * r
a(c3, 4) = i
End Select
End If
Next i
Range("G2") = Timer - start
Cells(2, 2).Resize(r, 4) = a
End Sub
Bookmarks