VBA Excel Example

Sub Summary()
'Worksheets("PETUNJUK PENGISIAN").Range("A6").Value = "Hello World"

Dim n As Integer
Dim AccountCode As String
Dim Kode As String
Dim Last3Kode As String
Dim MinyakPelumas As Double
Dim MinyakPelumasVal(1 To 12) As Double
Dim MaterialVal(1 To 12) As Double
Dim JasaVal(1 To 12) As Double
Dim KepegawaianVal(1 To 12) As Double
Dim PenyusutanVal(1 To 12) As Double
Dim AdmVal(1 To 12) As Double
Dim BiayaVal(1 To 12) As Double
Dim PendapatanVal(1 To 12) As Double

Dim PPTenagaListrikVal(1 To 12) As Double
Dim RetribusiVal(1 To 12) As Double
Dim ColTrxMonth(1 To 12) As Integer
Dim ColRealMonth(1 To 12) As String

ColTrxMonth(1) = 2
ColTrxMonth(2) = 8
ColTrxMonth(3) = 9
ColTrxMonth(4) = 10
ColTrxMonth(5) = 11
ColTrxMonth(6) = 12
ColTrxMonth(7) = 13
ColTrxMonth(8) = 14
ColTrxMonth(9) = 15
ColTrxMonth(10) = 3
ColTrxMonth(11) = 4
ColTrxMonth(12) = 5

ColRealMonth(1) = "E"
ColRealMonth(2) = "F"
ColRealMonth(3) = "G"
ColRealMonth(4) = "H"
ColRealMonth(5) = "I"
ColRealMonth(6) = "J"
ColRealMonth(7) = "K"
ColRealMonth(8) = "L"
ColRealMonth(9) = "M"
ColRealMonth(10) = "N"
ColRealMonth(11) = "O"
ColRealMonth(12) = "P"

MinyakPelumas = 0

LastRow = Cells(Rows.Count, "A").End(xlUp).Row 'Get Last Row

'MsgBox LastRow
For n = 2 To LastRow
   AccountCode = Cells(n, 1)
   Kode = Mid(AccountCode, 12, 1)
   Last3Kode = Mid(AccountCode, 13, 3)

  If Kode = "K" Then
           If Last3Kode = "101" Or Last3Kode = "102" Or Last3Kode = "103" Or Last3Kode = "104" Or Last3Kode = "105" Or Last3Kode = "106" Or Last3Kode = "107" Or Last3Kode = "199" Then
                   For m = 1 To 12
                        PendapatanVal(m) = PendapatanVal(m) + Cells(n, ColTrxMonth(m))
                   Next
           End If

   End If

   If Kode = "L" Then
           If Last3Kode = "102" Then
                   For m = 1 To 12
                        PendapatanVal(m) = PendapatanVal(m) + Cells(n, ColTrxMonth(m))
                   Next
           End If

   End If
   
   
   
Next



For m = 1 To 12
    Worksheets("REALISASI").Range(ColRealMonth(m) & "47").Value = BiayaVal(m)
            
Next
'Worksheets("REALISASI").Cells(4 + m, 30).Value = MinyakPelumasVal(m)
'Worksheets("REALISASI").Cells(m, 30).Value = MinyakPelumasVal(m - 4)
'Worksheets("REALISASI").Range("E30").Value = MinyakPelumas
'MsgBox MinyakPelumasVal(1)
'MsgBox RetribusiVal(1)




End Sub


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: