- Katılım
- 15 Mart 2005
- Mesajlar
- 382
- Excel Vers. ve Dili
- Microsoft 2016 En 64 Bit
- Altın Üyelik Bitiş Tarihi
- 20-03-2024
Merhaba,
Aşağıdaki kodları dener misiniz.
Aşağıdaki kodları dener misiniz.
C++:
Sub yillik_hrk_raporu()
Dim s1, s2 As Worksheet
Dim data1, data2, data3, data4, crite, crite2 As String
Dim r, lRow1 As Long
Dim tBorc, tAlc, tAlcKum, tBrcKum, bakiye As Double
Dim c, lRow2 As Byte
Application.ScreenUpdating = False
Set s1 = ThisWorkbook.Sheets("kayıt")
Set s2 = ThisWorkbook.Sheets("Rapor")
lRow1 = s1.Cells(Rows.Count, 2).End(xlUp).Row
lRow2 = s2.Cells(Rows.Count, 2).End(xlUp).Row
data1 = s1.Name & "!" & s1.Range("B5:B" & lRow1).Address
data2 = s1.Name & "!" & s1.Range("E5:E" & lRow1).Address
data3 = s1.Name & "!" & s1.Range("F5:F" & lRow1).Address
data4 = s1.Name & "!" & s1.Range("G5:G" & lRow1).Address
crite2 = s2.Range("B3").Address
s2.Range(s2.Range("C4"), s2.Range("P" & lRow2)).ClearContents
For r = 4 To lRow2 'Para birimine göre satırlarda döner
crite = s2.Cells(r, "B").Address
tBrcKum = Evaluate("=SUMPRODUCT(--(" & data2 & " = " & crite & "), --(YEAR(" & data1 & ") = " & crite2 & "), --(" & data3 & "))")
tAlcKum = Evaluate("=SUMPRODUCT(--(" & data2 & " = " & crite & "), --(YEAR(" & data1 & ") = " & crite2 & "), --(" & data4 & "))")
toplam = 0
For c = 3 To 15 'Devir ve Aylar sütununda döner
If c = 3 Then 'Devir kısmına girer
tBorc = Evaluate("=SUMPRODUCT(--(" & data2 & "=" & crite & "), --(YEAR(" & data1 & ") < " & crite2 & "), --(" & data3 & "))")
tAlc = Evaluate("=SUMPRODUCT(--(" & data2 & "=" & crite & "), --(YEAR(" & data1 & ") < " & crite2 & "), --(" & data4 & "))")
tBrcKum = tBrcKum + tBorc
tAlcKum = tAlcKum + tAlc
bakiye = WorksheetFunction.Min(tAlcKum, tBrcKum)
Else 'Aylar kısmına girer
tBorc = Evaluate("=SUMPRODUCT(--(" & data2 & "=" & crite & "),--(Month(" & data1 & ")=" & CByte((c - 3)) & "), --(YEAR(" & data1 & ")=" & crite2 & "), --(" & data3 & "))")
tAlc = Evaluate("=SUMPRODUCT(--(" & data2 & "=" & crite & "),--(Month(" & data1 & ")=" & CByte((c - 3)) & "), --(YEAR(" & data1 & ")=" & crite2 & "), --(" & data4 & "))")
End If
If s2.Cells(1, "A") = "Borç" Then
s2.Cells(r, c) = tBorc
ElseIf s2.Cells(1, "A") = "Alacak" Then
s2.Cells(r, c) = tAlc
ElseIf s2.Cells(1, "A") = "Bakiye" Then
s2.Cells(r, c) = tBorc - tAlc
ElseIf s2.Cells(1, "A") = "Mahsup" Then
If (tAlcKum - tBrcKum) > 0 Then
If tAlc > 0 Then
If tAlc <= bakiye Then
bakiye = bakiye - tAlc
Else
s2.Cells(r, c) = -(tAlc - bakiye)
bakiye = 0
End If
End If
Else
If tBorc > 0 Then
If tBorc <= bakiye Then
bakiye = bakiye - tBorc
Else
s2.Cells(r, c) = tBorc - bakiye
bakiye = 0
End If
End If
End If
End If
toplam = toplam + s2.Cells(r, c)
Next c
s2.Cells(r, c) = toplam
Next r
Application.ScreenUpdating = True
End Sub
Son düzenleme: