"Disabling" calculation of certain formulas until source cells updated -- is there a better way to do this?

d0rian

Active Member
Joined
May 30, 2015
Messages
313
Office Version
  1. 365
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.

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
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"

Forum statistics

Threads
1,223,888
Messages
6,175,206
Members
452,618
Latest member
Tam84

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