Materi Perkuliahan
Membuat Media dasar bilangan prima VBA Excel
Private Sub CommandButton1_Click()
Dim a As Integer
Dim b As Integer
Dim c As Integer
Dim i As Integer
Dim j As Integer
Dim k As Integer
a = Range(“C3”)
b = Range(“E3”)
If a <= 2 Then
Range(“A4”) = “1”
Range(“C5”) = “2”
Else
If a > 2 Then
Range(“A4”) = “0”
End If
End If
For i = a To b
For j = 2 To i – 1
If j = i – 1 Then
Range(“A4”) = Range(“A4”) + 1
c = Range(“A4”)
Range(“C” & 4 + c) = i
Exit For
Else
If i Mod j = 0 Then
Exit For
End If
End If
Next j
Next i
End Sub
- Tombol Hapus
Private Sub CommandButton2_Click()
Range(“C5:C100000”) = “”
Range(“A4”) = “0”
End Sub