Categories

Jumat, 26 Maret 2010

Membuat deret bilangan 1-200 dengan VBA

Function DeretAsli(Angka As Integer)
Dim i As Integer
For i = 1 To Angka
DeretAsli = DeretAsli + i
Next i
End Function
Function DeretGanjil(Angka As Integer)
Dim i As Integer
For i = 1 To Angka Step 2
DeretGanjil = DeretGanjil + i
Next i
End Function
Function DeretGenap(Angka As Integer)
Dim i As Integer
For i = 2 To Angka Step 2
DeretGenap = DeretGenap + i
Next i
End Function
Sub Asli()
Dim X As Integer, z As Integer, Y As Byte
X = InputBox("Masukan Nilai Suku terakhir :", "Deret bil asli dari 1-200")
If X > 200 Then
MsgBox ("Angka yang harus dimasukan 1-200")
Exit Sub
End If
Cells(1, 1) = "Deret bilanang asli sampai angka " & X & " adalah:"
For Y = 1 To X
Cells(2, Y).Value = Y
Next Y
Cells(2, X + 1) = " Jumlah= " & DeretAsli(X)
End Sub
Sub Ganjil()
Dim X As Integer, z As Integer, Y As Byte
X = InputBox("Masukan Nilai Suku terakhir :", "Deret bilangan Ganjil dari 1-200")
If X > 200 Then
MsgBox ("Angka yang harus dimasukan 1-200")
Exit Sub
End If
Cells(1, 1) = "Deret bilanang Ganjil sampai angka " & X & " adalah:"
For Y = 1 To X Step 2
Cells(3, Y).Value = Y
Next Y
Cells(3, X + 1) = " Jumlah= " & DeretGanjil(X)
End Sub
Sub Genap()
Dim X As Integer, z As Integer, Y As Byte
X = InputBox("Masukan Nilai Suku terakhir :", "Deret bil Genap dari 1-200")
If X > 200 Then
MsgBox ("Angka yang harus dimasukan 1-200")
Exit Sub
End If
Cells(1, 1) = "Deret bilanang Genap sampai angka " & X & " adalah:"
For Y = 2 To X Step 2
Cells(4, Y).Value = Y
Next Y
Cells(4, X + 1) = " Jumlah= " & DeretGenap(X)
End Sub

perihal: Google (lihat di Google Wikipinggir)

1 komentar: