optimize etmeye çalışırken tek bir kod yöntemine döngüye odaklanmayın. Mesela aşağıdaki kod ile kendi kodunuzu karşılaştırın örnek olarak sizin kodlarınızı kısmen optimize edecek olursak:
Kod:
Dim ws1 As Worksheet, ws2 As Worksheet, wsAyar As Worksheet
Dim dataRange As Range
Dim resultRange As Range
Dim lastRow As Long
Dim i As Long
Dim puDizi() As Variant
Dim m As Long
Dim b As Double, c As Double, d As Double, e As Double, f As Double, bel As Double
Dim isim As String
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Application.DisplayAlerts = False
Application.EnableEvents = False
Set ws1 = ThisWorkbook.Sheets("Sayfa1")
Set ws2 = ThisWorkbook.Sheets("Sayfa37")
Set wsAyar = ThisWorkbook.Sheets("Ayar")
lastRow = ws1.Cells(ws1.Rows.Count, 4).End(xlUp).Row
Set dataRange = ws1.Range("A4:N" & lastRow)
Set resultRange = ws2.Range("A3:N5000")
resultRange.Clear
m = -1
ReDim puDizi(100, 13)
For i = 1 To dataRange.Rows.Count
If dataRange.Cells(i, 2).Value = True Then
isim = dataRange.Cells(i, 4).Value
m = m + 1
End If
If dataRange.Cells(i, 4).Value = isim Then
' Verileri işle
If dataRange.Cells(i, 5) <> "" Then
puDizi(m, 2) = dataRange.Cells(i, 5).Value
End If
Select Case dataRange.Cells(i, 12).Value
Case "101"
b = dataRange.Cells(i, dataRange.Columns.Count).Value
Case "119"
c = dataRange.Cells(i, dataRange.Columns.Count).Value
Case "103"
f = dataRange.Cells(i, dataRange.Columns.Count).Value
Case "117"
d = dataRange.Cells(i, dataRange.Columns.Count).Value
Case "116"
e = dataRange.Cells(i, dataRange.Columns.Count).Value
Case "106"
bel = dataRange.Cells(i, dataRange.Columns.Count).Value
End Select
End If
puDizi(m, 0) = m + 1
puDizi(m, 1) = isim
puDizi(m, 3) = b
puDizi(m, 4) = c
puDizi(m, 5) = f
puDizi(m, 6) = d
puDizi(m, 7) = e
puDizi(m, 8) = bel
puDizi(m, 13) = b + c + d + e + f + bel
Next i
resultRange.Resize(m + 1, UBound(puDizi, 2)).Value = puDizi
resultRange.Borders.LineStyle = xlSolid
resultRange.HorizontalAlignment = xlCenter
' Diğer işlemler
' ...
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
Application.DisplayAlerts = True
Application.EnableEvents = True