I have a rather large (15MB) file that streams in a ton of real-time stock quotes time via a brokerage API, and runs a bunch of calculations / conditional formatting as the quotes update tick-by-tick. There's quite a lag, but I've put a lot of work into optimizing my file for performance despite its resource intensiveness.
In the hopes of further improving performance, I want to disable any unnecessary formulas / calculations. E.g. There are many formulas on background sheets that need to be active at the beginning of the day when I import and clean yesterday's closing prices; or others that I'll run a few times throughout the day, but which DON'T need to be 'on' all day. TLDR: the only formulas I want active are the ones necessary for running calculations on the real-time stock quotes that are coming in and updating tick-by-tick via API.
Here's the somewhat clunky solution I've implemented, but I want to know whether Excel perhaps has some native feature that might make this unnecessary. The below is an example of formulas that exist on a background sheet that I *don't* need running -- I copy the formula range ("imp_YP_formgrab" currently in cells S1:AA1) down to "imp_YP_pasterange" (S2:S500), and then copy/paste-values to hardcode the results.
So my 'solution' is the TWO "REPLACE" functions in the VBA below -- which essentially "deactivates" my formulas after they have been run by replacing the equals sign at the beginning (=IF) with an underscore (_IF), thus turning them into plain text, after they have been run. (And then I 'activate' them by doing the inverse at the start of the code.)
Is there a more elegant way of doing this? The truth is I don't even know if this is going to actually streamline my file all that much or improve performance...but it seems to me that ANY formulas calculating unnecessarily in the background are going to be a drain on limited resources. And there are probably ~400 cells scattered throughout my worksheet that are 'active' formulas that technically don't need to be continuously on.
In the hopes of further improving performance, I want to disable any unnecessary formulas / calculations. E.g. There are many formulas on background sheets that need to be active at the beginning of the day when I import and clean yesterday's closing prices; or others that I'll run a few times throughout the day, but which DON'T need to be 'on' all day. TLDR: the only formulas I want active are the ones necessary for running calculations on the real-time stock quotes that are coming in and updating tick-by-tick via API.
Here's the somewhat clunky solution I've implemented, but I want to know whether Excel perhaps has some native feature that might make this unnecessary. The below is an example of formulas that exist on a background sheet that I *don't* need running -- I copy the formula range ("imp_YP_formgrab" currently in cells S1:AA1) down to "imp_YP_pasterange" (S2:S500), and then copy/paste-values to hardcode the results.
So my 'solution' is the TWO "REPLACE" functions in the VBA below -- which essentially "deactivates" my formulas after they have been run by replacing the equals sign at the beginning (=IF) with an underscore (_IF), thus turning them into plain text, after they have been run. (And then I 'activate' them by doing the inverse at the start of the code.)
Is there a more elegant way of doing this? The truth is I don't even know if this is going to actually streamline my file all that much or improve performance...but it seems to me that ANY formulas calculating unnecessarily in the background are going to be a drain on limited resources. And there are probably ~400 cells scattered throughout my worksheet that are 'active' formulas that technically don't need to be continuously on.
VBA Code:
Sub imp_YPquotes_refr_conn()
Application.ScreenUpdating = False
Range(Range("imp_YP_pasterange").Value).ClearContents
Range("impYP_A_to_Q").Clear
ThisWorkbook.Connections("quotes").Refresh
Range("imp_YP_formgrab").Replace What:="_IF", Replacement:="=IF", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False[/B]
Range("imp_YP_formgrab").Copy
Range(Range("imp_YP_pasterange").Value).PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range(Range("imp_YP_pasterange").Value).Copy
Range(Range("imp_YP_pasterange").Value).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("imp_YP_formgrab").Replace What:="=IF", Replacement:="_IF", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Application.CutCopyMode = False
Application.ScreenUpdating = True
End Sub