Excelで,Visual Basic Editor にペーストして実行してください!
Sub 素数表作成()
Cells.Select
Selection.ClearContents
Dim n As Long
n = CInt(InputBox("n="))
Dim i As Long
dim l as long
Dim k As Long
Dim s As Long
k = 1
Cells(k, 1).Value = "番号"
Cells(k, 2).Value = "素数"
k = 2
Cells(k, 1).Value = 1
Cells(k, 2).Value = 2
k = 3
For j = 3 To 2 * n - 1 Step 2
s = 0
For i = 3 To Int(Sqr(j)) Step 2
If j Mod i = 0 Then
s = s + 1
End If
Next i
If s < 1 Then
Cells(k, 1).Value = k - 1
Cells(k, 2).Value = j
k = k + 1
End If
Next j
Range("A1").Select
End Sub