Materi Perkuliahan

Membuat Data Uang Kas Sederhana VBA Excel

Dipublikasikan pada : 29 Januari 2020.

Private Sub CommandButton1_Click()
Dim sheets As Worksheet
Set sheets = Worksheets(2)

Dim alamat As Range
Dim nilai As Integer
nilai = sheets.Cells(sheets.Rows.Count, “b”).End(xlUp).Row
sheets.Range(“c” & nilai + 1) = Range(“D6”)
sheets.Range(“c” & nilai + 1).HorizontalAlignment = xlCenter
sheets.Range(“c” & nilai + 1).VerticalAlignment = xlCenter

sheets.Range(“d” & nilai + 1) = Range(“D8”)
sheets.Range(“d” & nilai + 1).HorizontalAlignment = xlCenter
sheets.Range(“d” & nilai + 1).VerticalAlignment = xlCenter

If Range(“D10”) = “INCOME” Then
sheets.Range(“e” & nilai + 1) = Range(“D12”)
sheets.Range(“e” & nilai + 1).HorizontalAlignment = xlCenter
sheets.Range(“e” & nilai + 1).VerticalAlignment = xlCenter
ElseIf Range(“D10”) = “OUTCOME” Then
sheets.Range(“f” & nilai + 1) = Range(“D12”)
sheets.Range(“f” & nilai + 1).HorizontalAlignment = xlCenter
sheets.Range(“f” & nilai + 1).VerticalAlignment = xlCenter
End If

sheets.Range(“b” & nilai + 1) = nilai – 1
sheets.Range(“b” & nilai + 1).HorizontalAlignment = xlCenter
sheets.Range(“b” & nilai + 1).VerticalAlignment = xlCenter

sheets.Range(“g” & nilai + 1).Font.Color = vbBlack
sheets.Range(“g” & nilai + 1).HorizontalAlignment = xlCenter
sheets.Range(“g” & nilai + 1).VerticalAlignment = xlCenter

Range(“D6”) = “”
Range(“D8”) = “”
Range(“D10”) = “”
Range(“D12”) = “”

End Sub

id_IDIndonesian