Bomino
Member
Hello
I am a newbie and I was wondering if you could help me optimize the following code.
Thanks.
I am a newbie and I was wondering if you could help me optimize the following code.
Thanks.
Code:
Sub faster()
Dim ws As Worksheet
With Application
.DisplayAlerts = False
.EnableEvents = False
.ScreenUpdating = False
.Calculation = xlCalculationManual
End With
Set ws = ThisWorkbook.Worksheets("Calculations")
With ws.Range("C3:C54")
.FormulaR1C1 = "=IF(SUMIF(dtWeekEnded,RC[-1],TotalWages)=0,NA(),SUMIF(dtWeekEnded,RC[-1],TotalWages))"
.Value = .Value
End With
With ws.Range("C3:C54")
.FormulaR1C1 = "=IF(SUMIF(dtWeekEnded,RC[-1],TotalWages)=0,NA(),SUMIF(dtWeekEnded,RC[-1],TotalWages))"
.Value = .Value
End With
With ws.Range("D3:D54")
.FormulaR1C1 = "=IF(VLOOKUP(RC[-2],Look1,4,FALSE)=0,NA(),VLOOKUP(RC[-2],Look1,4,FALSE))"
.Value = .Value
End With
With ws.Range("E3:E54")
.FormulaR1C1 = "=RC[-1]-RC[-2]"
.Value = .Value
End With
With ws.Range("F3:F54")
.FormulaR1C1 = "=IF(SUMIF(dtWeekEnded,RC[-4],OTHours)=0,NA(),SUMIF(dtWeekEnded,RC[-4],OTHours))"
.Value = .Value
End With
With ws.Range("g3:g54")
.FormulaR1C1 = "=SUMIF(dtWeekEnded,RC[-5],RegHours)"
.Value = .Value
End With
With ws.Range("H3:H54")
.FormulaR1C1 = "=1.5*RC[-2]+RC[-1]"
.Value = .Value
End With
With ws.Range("I3:I54")
.FormulaR1C1 = "=IF(RC[-1]=0,0,RC[-3]/RC[-1])"
.Value = .Value
End With
With ws.Range("J3:J54")
.FormulaR1C1 = "=RC[-2]/40"
.Value = .Value
End With
With ws.Range("K3:K54")
.FormulaR1C1 = "=IF(Collection!R[-1]C[-5]=0,NA(),Collection!R[-1]C[-5])"
.Value = .Value
End With
With ws.Range("K3:K54")
.FormulaR1C1 = "=IF(Collection!R[-1]C[-5]=0,NA(),Collection!R[-1]C[-5])"
.Value = .Value
End With
With ws.Range("L3:L54")
.FormulaR1C1 = "=SUMIF(TMDATE,RC[-10],TMRGHRS)"
.Value = .Value
End With
With ws.Range("M3:M54")
.FormulaR1C1 = "=SUMIF(TMDATE,RC[-11],TMOTHRS)"
.Value = .Value
End With
With ws.Range("N3:N54")
.FormulaR1C1 = "=IF((RC[-2]+RC[-1])=0,NA(),(RC[-2]+RC[-1]))"
.Value = .Value
End With
With ws.Range("O3:O54")
.FormulaR1C1 = "=RC[-7]+RC[-1]"
.Value = .Value
End With
With ws.Range("P3:p54")
.FormulaR1C1 = "=IF(RC[-1]=0,"""",RC[-10]/RC[-1])"
.Value = .Value
End With
With ws.Range("Q3:Q54")
.FormulaR1C1 = "=IF(RC[-2]=0,"""",RC[-2]/40)"
.Value = .Value
End With
With Application
.DisplayAlerts = True
.EnableEvents = True
.ScreenUpdating = True
.Calculation = xlCalculationAutomatic
End With
End Sub
Last edited by a moderator: