Hi All,
I'm having some trouble speeding up my VBA code. Below is the current code I have that works perfectly, but takes a while to fill down and calculate.
I tried changing it to the below, but Evaluate is giving me a hard time and giving me #Value
hoping I can get some help on this one!
I'm having some trouble speeding up my VBA code. Below is the current code I have that works perfectly, but takes a while to fill down and calculate.
Code:
Dim lastRow As Long
Dim strFormulas(1 To 3) As Variant
Dim sh As Worksheet
lastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
With ThisWorkbook.Sheets("Agreement Product Print")
strFormulas(1) = "=VLOOKUP(RC[-2],Sheet2!C[-54]:C[-53],2,FALSE)"
strFormulas(2) = "=VLOOKUP(RC[-2],Sheet2!C[-55]:C[-54],2,FALSE)"
strFormulas(3) = "=RC[-56]&RC[-16]"
'
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = True
Range("BC16:BE16").Formula = strFormulas
End With
Range("BF16").Select
Selection.FormulaArray = "=MIN(IF(RC57:R100000C57=RC[-1],RC56:R100000C56))"
Range("$BC$16:$BE" & lastRow).FillDown
Range("$BF$16:$BF" & lastRow).FillDown
For Each sh In ActiveWorkbook.Sheets
sh.Calculate
Next sh
I tried changing it to the below, but Evaluate is giving me a hard time and giving me #Value
Code:
Dim lastRow As Long
Dim strFormulas(1 To 3) As Variant
Dim sh As Worksheet
lastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
With ThisWorkbook.Sheets("Agreement Product Print")
strFormulas(1) = "=VLOOKUP(RC[-2],Sheet2!C[-54]:C[-53],2,FALSE)"
strFormulas(2) = "=VLOOKUP(RC[-2],Sheet2!C[-55]:C[-54],2,FALSE)"
strFormulas(3) = "=RC[-56]&RC[-16]"
'
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = True
Range("BC16:BE16").Formula = strFormulas
End With
With Range("BF16:BF" & lastRow)
FormulaArray = Evaluate("MIN(IF($BE$16:$B$" & lastRow & ")=C1,$BE$16:$B$" & lastRow & ",""""))")
End With
Range("$BC$16:$BE" & lastRow).FillDown
For Each sh In ActiveWorkbook.Sheets
sh.Calculate
Next sh
hoping I can get some help on this one!