Large file applying formulas via VBA help

ItalianPlatinum

Well-known Member
Joined
Mar 23, 2017
Messages
880
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
I have a large file, and i moved the formulas into VBA looking to help the speed but it isn't much improvement. I was able to narrow down the formula to one formula that is taking the most time. Does anyone have any suggestions to help alleviate this? i am up for anything. the file has 400k rows and 18 columns. columns S-AA i set the formulas.

VBA Code:
    .Range("W5:W" & lr).Formula = "=IF(AND(U5=TRUE,V5=TRUE),I5,WORKDAY(I5,1,HOLIDAYS!A$1:A$65536))"

VBA Code:
'formatting for recon sheet'formatting and formulas for recon sheet
With WsCalc
    lr = .Cells(Rows.Count, "A").End(xlUp).Row
    .Range("S5:S" & lr).Formula = "=IF(L5>19000000,""Y"",""N"")"
    .Range("T5:T" & lr).Formula = "=H5-G5"
    .Range("U5:U" & lr).Formula = "=I5=H5"
    .Range("V5:V" & lr).Formula = "=I5=J5"
    .Range("W5:W" & lr).Formula = "=IF(AND(U5=TRUE,V5=TRUE),I5,WORKDAY(I5,1,HOLIDAYS!A$1:A$65536))"
    .Range("X5:X" & lr).Formula = "=IF(WEEKDAY(G5,2)>=5,""Y"",""N"")"
    .Range("Y5:Y" & lr).Formula = "=IF(AND(U5=TRUE,V5=TRUE),""Y"",""N"")"
    .Range("Z5:Z" & lr).Formula = "=IF(I5<>J5,""Y"",""N"")"
    .Range("AA5:AA" & lr).Formula = "=IF(AND(S5=""N"",T5>0,X5=""N""),""Y"",""N"")"
    .Range("S5:AA" & lr).Value = .Range("S5:AA" & lr).Value
    .Columns("A:AA").EntireColumn.AutoFit
    '.Range("2:2").AutoFilter 20, "Yes"
    .Application.Goto Reference:=.Range("A1"), Scroll:=True
    .Activate
End With

also thanks in advance :)
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
.Range("W5:W" & lr).Formula = "=IF(AND(U5=TRUE,V5=TRUE),I5,WORKDAY(I5,1,HOLIDAYS!A$1:A$65536))"
It's kind of lookup function/feature. The always slow down

Best is to make calculations to manual in settings and see the difference...
 
Upvote 0
Do you really need to use 65k rows for holidays??
 
Upvote 0
I need to assess each date in each row if the date is a business day (working day). I dont know another way to do that.
 
Upvote 0
Do you really have 65k rows of holiday dates? If not, why use HOLIDAYS!A$1:A$65536
 
Upvote 0
Solution
Also, since you're doing the same calculation in column Y that you did at the start of the column W formula, you should swap them round and just use the Y result in W

VBA Code:
    .Range("Y5:Y" & lr).Formula = "=IF(AND(U5=TRUE,V5=TRUE),""Y"",""N"")"
    .Range("W5:W" & lr).Formula = "=IF(Y5=""Y"",I5,WORKDAY(I5,1,HOLIDAYS!A$1:A$65536))"
    .Range("X5:X" & lr).Formula = "=IF(WEEKDAY(G5,2)>=5,""Y"",""N"")"
 
Upvote 0
Also, since you're doing the same calculation in column Y that you did at the start of the column W formula, you should swap them round and just use the Y result in W

VBA Code:
    .Range("Y5:Y" & lr).Formula = "=IF(AND(U5=TRUE,V5=TRUE),""Y"",""N"")"
    .Range("W5:W" & lr).Formula = "=IF(Y5=""Y"",I5,WORKDAY(I5,1,HOLIDAYS!A$1:A$65536))"
    .Range("X5:X" & lr).Formula = "=IF(WEEKDAY(G5,2)>=5,""Y"",""N"")"
so you mean just combine the formulas? i was afraid that would take longer so i broke it out
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top