- Katılım
- 17 Ekim 2017
- Mesajlar
- 110
- Excel Vers. ve Dili
- Microsoft Office 2013 Standard
DOSYA İndirmek/Yüklemek için ÜCRETLİ ALTIN ÜYELİK Gereklidir!
Altın Üyelik Hakkında Bilgi
Sub test()
Dim veriCH, veriSat, yil$, yillar, i&, ii%, son&, tmp, sut%, raporTablo, kod$, sat&, ySat&
With Sheets("CH HESAPLAR")
veriCH = .Range("A1:G" & .Cells(Rows.Count, 1).End(3).Row).Value
End With
With Sheets("SATIŞLAR")
son = .Cells(Rows.Count, 1).End(3).Row
veriSat = .Range("A2:E" & .Cells(Rows.Count, 1).End(3).Row).Value
End With
With CreateObject("Scripting.Dictionary")
For i = 1 To UBound(veriSat)
If veriSat(i, 1) <> "" Then
yil = Year(veriSat(i, 1))
If Not .exists(yil) Then .Item(yil) = Null
End If
Next i
yillar = .KEYS
For i = 0 To UBound(yillar) - 1
For ii = i + 1 To UBound(yillar)
If yillar(ii) < yillar(i) Then
tmp = yillar(ii)
yillar(ii) = yillar(i)
yillar(i) = tmp
End If
Next ii
Next i
.RemoveAll
sut = UBound(yillar) + 2
ReDim raporTablo(1 To UBound(veriCH), 1 To 5 + sut)
sut = 6
For Each tmp In yillar
.Item("_" & tmp) = sut
raporTablo(1, sut) = tmp & " TOPLAM SATIŞ"
sut = sut + 1
Next tmp
.Item("_" & "Toplam") = sut
raporTablo(1, sut) = "TOPLAM SATIŞ TUTARI"
raporTablo(1, 1) = "CH KODU"
raporTablo(1, 2) = "CH Ünvanı"
raporTablo(1, 3) = "Cari Yetki Kodu"
raporTablo(1, 4) = "Bakiye"
raporTablo(1, 5) = "Bakiye Tipi"
sat = 1
For i = 2 To UBound(veriCH)
If veriCH(i, 1) <> "" Then
kod = veriCH(i, 2)
If Not .exists(kod) Then
sat = sat + 1
.Item(kod) = sat
raporTablo(sat, 1) = kod
raporTablo(sat, 2) = veriCH(i, 3)
raporTablo(sat, 3) = veriCH(i, 1)
raporTablo(sat, 4) = veriCH(i, 6)
raporTablo(sat, 5) = veriCH(i, 7)
End If
End If
Next i
For i = 1 To UBound(veriSat)
If veriSat(i, 1) <> "" Then
yil = "_" & Year(veriSat(i, 1))
tmp = .Item(yil)
ySat = CInt(.Item(veriSat(i, 3)))
raporTablo(ySat, tmp) = raporTablo(ySat, tmp) + veriSat(i, 5)
tmp = .Item("_Toplam")
raporTablo(ySat, tmp) = raporTablo(ySat, tmp) + veriSat(i, 5)
End If
Next i
End With
With Sheets("RAPOR")
.Cells.Clear
.Range("A1").Resize(sat, sut).Value = raporTablo
.Range("D2:D" & sat).NumberFormat = "#,##0.00 $"
.Range("F2").Resize(sat, sut - 5).NumberFormat = "#,##0.00 $"
With .Range("A1")
With .Resize(, sut)
.WrapText = True
.EntireRow.RowHeight = 30
.ColumnWidth = 15
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.Font.Bold = True
.Interior.Color = rgbAliceBlue
End With
With .CurrentRegion
.EntireColumn.AutoFit
.EntireRow.AutoFit
.Borders.LineStyle = xlContinuous
.Sort key1:=Cells(3), Header:=xlYes
End With
End With
End With
End Sub

EDIT : Power Query Sorgusu ve makro bulunan dosya eklendi.Kod:Sub test() Dim veriCH, veriSat, yil$, yillar, i&, ii%, son&, tmp, sut%, raporTablo, kod$, sat&, ySat& With Sheets("CH HESAPLAR") veriCH = .Range("A1:G" & .Cells(Rows.Count, 1).End(3).Row).Value End With With Sheets("SATIŞLAR") son = .Cells(Rows.Count, 1).End(3).Row veriSat = .Range("A2:E" & .Cells(Rows.Count, 1).End(3).Row).Value End With With CreateObject("Scripting.Dictionary") For i = 1 To UBound(veriSat) If veriSat(i, 1) <> "" Then yil = Year(veriSat(i, 1)) If Not .exists(yil) Then .Item(yil) = Null End If Next i yillar = .KEYS For i = 0 To UBound(yillar) - 1 For ii = i + 1 To UBound(yillar) If yillar(ii) < yillar(i) Then tmp = yillar(ii) yillar(ii) = yillar(i) yillar(i) = tmp End If Next ii Next i .RemoveAll sut = UBound(yillar) + 2 ReDim raporTablo(1 To UBound(veriCH), 1 To 5 + sut) sut = 6 For Each tmp In yillar .Item("_" & tmp) = sut raporTablo(1, sut) = tmp & " TOPLAM SATIŞ" sut = sut + 1 Next tmp .Item("_" & "Toplam") = sut raporTablo(1, sut) = "TOPLAM SATIŞ TUTARI" raporTablo(1, 1) = "CH KODU" raporTablo(1, 2) = "CH Ünvanı" raporTablo(1, 3) = "Cari Yetki Kodu" raporTablo(1, 4) = "Bakiye" raporTablo(1, 5) = "Bakiye Tipi" sat = 1 For i = 2 To UBound(veriCH) If veriCH(i, 1) <> "" Then kod = veriCH(i, 2) If Not .exists(kod) Then sat = sat + 1 .Item(kod) = sat raporTablo(sat, 1) = kod raporTablo(sat, 2) = veriCH(i, 3) raporTablo(sat, 3) = veriCH(i, 1) raporTablo(sat, 4) = veriCH(i, 6) raporTablo(sat, 5) = veriCH(i, 7) End If End If Next i For i = 1 To UBound(veriSat) If veriSat(i, 1) <> "" Then yil = "_" & Year(veriSat(i, 1)) tmp = .Item(yil) ySat = CInt(.Item(veriSat(i, 3))) raporTablo(ySat, tmp) = raporTablo(ySat, tmp) + veriSat(i, 5) tmp = .Item("_Toplam") raporTablo(ySat, tmp) = raporTablo(ySat, tmp) + veriSat(i, 5) End If Next i End With With Sheets("RAPOR") .Cells.Clear .Range("A1").Resize(sat, sut).Value = raporTablo .Range("D2:D" & sat).NumberFormat = "#,##0.00 $" .Range("F2").Resize(sat, sut - 5).NumberFormat = "#,##0.00 $" With .Range("A1") With .Resize(, sut) .WrapText = True .EntireRow.RowHeight = 30 .ColumnWidth = 15 .HorizontalAlignment = xlCenter .VerticalAlignment = xlCenter .Font.Bold = True .Interior.Color = rgbAliceBlue End With With .CurrentRegion .EntireColumn.AutoFit .EntireRow.AutoFit .Borders.LineStyle = xlContinuous .Sort key1:=Cells(3), Header:=xlYes End With End With End With End Sub