- Katılım
- 9 Eylül 2021
- Mesajlar
- 94
- Excel Vers. ve Dili
- 365TR
selamlar arkadaşlar
alttaki kodu çalıştırdığımda çok uzun sürüyor
bunu kısaltmak mümkün mü ?
alttaki kodu çalıştırdığımda çok uzun sürüyor
bunu kısaltmak mümkün mü ?
Kod:
Sub bakkal()
Dim i As Long
Dim zonsatir As Long
Dim ws As Worksheet
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Set ws = ThisWorkbook.Sheets("ZKPY")
zonsatir = ws.Cells(ws.Rows.Count, "D").End(xlUp).Row
For i = 1 To zonsatir
If ws.Cells(i, 6) = 1 Then
Call ALIS
Else
Call SATIS
End If
Next i
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub
Sub ALIS()
Dim ws As Worksheet
Dim lastRow As Long
Dim i As Long
Dim currentIsim As String
Dim toplam As Double
Dim nextRow As Long
Dim isim As String
Dim sayi As Double
Set ws = ThisWorkbook.Sheets("ZKPY")
lastRow = ws.Cells(ws.Rows.Count, "D").End(xlUp).Row
nextRow = 1
currentIsim = ws.Cells(1, "D").Value
toplam = 0
For i = 1 To lastRow
isim = ws.Cells(i, "D").Value
sayi = CDbl(ws.Cells(i, "C").Value)
If isim <> currentIsim Then
ws.Cells(nextRow, "K").Value = currentIsim
ws.Cells(nextRow, "L").Value = toplam
ws.Cells(nextRow, "J").Value = ws.Cells(i - 1, "B").Value
nextRow = nextRow + 1
currentIsim = isim
toplam = sayi
Else
toplam = toplam + sayi
End If
If i = lastRow Then
ws.Cells(nextRow, "K").Value = currentIsim
ws.Cells(nextRow, "L").Value = toplam
ws.Cells(nextRow, "J").Value = ws.Cells(i, "B").Value
End If
ws.Cells(i, "J").NumberFormat = "hh:mm:ss"
Next i
End Sub
Sub SATIS()
Dim ws As Worksheet
Dim lastRow As Long
Dim i As Long
Dim currentIsim As String
Dim toplam As Double
Dim nextRow As Long
Dim isim As String
Dim sayi As Double
Set ws = ThisWorkbook.Sheets("ZKPY")
lastRow = ws.Cells(ws.Rows.Count, "E").End(xlUp).Row
nextRow = 1
currentIsim = ws.Cells(1, "E").Value
toplam = 0
For i = 1 To lastRow
isim = ws.Cells(i, "E").Value
sayi = CDbl(ws.Cells(i, "C").Value)
If isim <> currentIsim Then
ws.Cells(nextRow, "P").Value = currentIsim
ws.Cells(nextRow, "Q").Value = toplam
ws.Cells(nextRow, "O").Value = ws.Cells(i - 1, "B").Value
nextRow = nextRow + 1
currentIsim = isim
toplam = sayi
Else
toplam = toplam + sayi
End If
If i = lastRow Then
ws.Cells(nextRow, "P").Value = currentIsim
ws.Cells(nextRow, "Q").Value = toplam
ws.Cells(nextRow, "O").Value = ws.Cells(i, "B").Value
End If
ws.Cells(i, "O").NumberFormat = "hh:mm:ss"
Next i
End Sub