Hi,
I have below macro code that runs extremely slow. i was wondering if there is a way to optimize and speed up the run time. Thanks
I have below macro code that runs extremely slow. i was wondering if there is a way to optimize and speed up the run time. Thanks
Code:
Sub MathYTDFORMBRANDAC()
Dim i As Integer, x As Integer, z As Integer, h As Integer, f As Integer, t As Integer
Dim condition As Range
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
With Sheets("AC")
For i = 74 To 83
.Cells(i, 30).Value = .Cells(i, 28).Value - .Cells(i, 29).Value
If .Cells(i, 29).Value <> 0 Then
.Cells(i, 31).Value = .Cells(i, 28).Value / .Cells(i, 29).Value - 1
End If
If .Range("AB74").Value <> 0 Then
.Cells(i, 32).Value = .Cells(i, 28).Value / .Range("AB74").Value * 100
End If
If .Range("AC74").Value <> 0 Then
.Cells(i, 33).Value = .Cells(i, 29).Value / .Range("AC74").Value * 100
End If
.Cells(i, 34).Value = .Cells(i, 32).Value - .Cells(i, 33).Value
For x = 84 To 97
.Cells(x, 30).Value = .Cells(x, 28).Value - .Cells(x, 29).Value
If .Cells(x, 29).Value <> 0 Then
.Cells(x, 31).Value = .Cells(x, 28).Value / .Cells(x, 29).Value - 1
End If
If .Range("AB84").Value <> 0 Then
.Cells(x, 32).Value = .Cells(x, 28).Value / .Range("AB84").Value * 100
End If
If .Range("AC84").Value <> 0 Then
.Cells(x, 33).Value = .Cells(x, 29).Value / .Range("AC84").Value * 100
End If
.Cells(x, 34).Value = .Cells(x, 32).Value - .Cells(x, 33).Value
For z = 98 To 106
.Cells(z, 30).Value = .Cells(z, 28).Value - .Cells(z, 29).Value
If .Cells(z, 29).Value <> 0 Then
.Cells(z, 31).Value = .Cells(z, 28).Value / .Cells(z, 29).Value - 1
End If
If .Range("AB98").Value <> 0 Then
.Cells(z, 32).Value = .Cells(z, 28).Value / .Range("AB98").Value * 100
End If
If .Range("AC98").Value <> 0 Then
.Cells(z, 33).Value = .Cells(z, 29).Value / .Range("AC98").Value * 100
End If
.Cells(z, 34).Value = .Cells(z, 32).Value - .Cells(z, 33).Value
For h = 107 To 115
.Cells(h, 30).Value = .Cells(h, 28).Value - .Cells(h, 29).Value
If .Cells(h, 29).Value <> 0 Then
.Cells(h, 31).Value = .Cells(h, 28).Value / .Cells(h, 29).Value - 1
End If
If .Range("AB107").Value <> 0 Then
.Cells(h, 32).Value = .Cells(h, 28).Value / .Range("AB107").Value * 100
End If
If .Range("AC107").Value <> 0 Then
.Cells(h, 33).Value = .Cells(h, 29).Value / .Range("AC107").Value * 100
End If
.Cells(h, 34).Value = .Cells(h, 32).Value - .Cells(h, 33).Value
For f = 116 To 120
.Cells(f, 30).Value = .Cells(f, 28).Value - .Cells(f, 29).Value
If .Cells(f, 29).Value <> 0 Then
.Cells(f, 31).Value = .Cells(f, 28).Value / .Cells(f, 29).Value - 1
End If
If .Range("AB116").Value <> 0 Then
.Cells(f, 32).Value = .Cells(f, 28).Value / .Range("AB116").Value * 100
End If
If .Range("AC116").Value <> 0 Then
.Cells(f, 33).Value = .Cells(f, 29).Value / .Range("AC116").Value * 100
End If
.Cells(f, 34).Value = .Cells(f, 32).Value - .Cells(f, 33).Value
For t = 121 To 127
.Cells(t, 30).Value = .Cells(t, 28).Value - .Cells(t, 29).Value
If .Cells(t, 29).Value <> 0 Then
.Cells(t, 31).Value = .Cells(t, 28).Value / .Cells(t, 29).Value - 1
End If
If .Range("AB121").Value <> 0 Then
.Cells(t, 32).Value = .Cells(t, 28).Value / .Range("AB121").Value * 100
End If
If .Range("AC121").Value <> 0 Then
.Cells(t, 33).Value = .Cells(t, 29).Value / .Range("AC121").Value * 100
End If
.Cells(t, 34).Value = .Cells(t, 32).Value - .Cells(t, 33).Value
Next t
Next f
Next h
Next z
Next x
Next i
End With
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub