続・素数

Sub Arrange_S()
    
    Cells.Select
    Selection.ClearContents
    Selection.Interior.ColorIndex = xlNone

    Dim lngN As Long
    lngN = 100
    
    Dim lngSieve() As Long
    ReDim lngSieve(1 To lngN)
        
    Call Sieve_S(lngSieve(), lngN)
    
    Range("A1").Select
    ActiveCell.Value = lngN
    
    Dim i As Long

    For i = 1 To lngN
        If i Mod 10 = 1 Then
            ActiveCell.Offset(1, 0).Select
        End If

        If i Mod 10 = 0 Then
            If lngSieve(i) <> 0 Then
                ActiveCell.Offset(0, 9).Interior.ColorIndex = 34
                ActiveCell.Offset(0, 9).Value = lngSieve(i)
            Else
                ActiveCell.Offset(0, 9).Interior.ColorIndex = 38
            End If
        Else
            If lngSieve(i) <> 0 Then
                ActiveCell.Offset(0, (i Mod 10) - 1).Interior.ColorIndex = 34
                ActiveCell.Offset(0, (i Mod 10) - 1).Value = i
            Else
                ActiveCell.Offset(0, (i Mod 10) - 1).Interior.ColorIndex = 38
            End If
        End If
    Next

End Sub


Public Sub Sieve_S(ByRef SIEVE() As Long, ByVal N As Long)

    Dim i As Long

    For i = 1 To N
        If i = 1 Then
            SIEVE(i) = 0
        Else
            SIEVE(i) = i
        End If
    Next

    Dim j As Long
    
    For i = 2 To Int(N / 2)
        For j = 1 To N
            If j Mod i = 0 Then
                If i <> j Then
                    SIEVE(j) = 0
                End If
            End If
        Next
    Next

End Sub

先日書いたマクロをお遊びでモジュール化(って言うほどのもんじゃないけど…。)してみました。
ただそれだけです。