+ Reply to Thread
Results 1 to 8 of 8

VBA: Formula to only run once?

  1. #1
    Registered User
    Join Date
    09-07-2017
    Location
    Southfield, MI
    MS-Off Ver
    2016
    Posts
    5

    VBA: Formula to only run once?

    Boy, I've seen many similar questions, but I just couldn't apply other answers to this:
    Using a simple formula in J88, =SUM(N88)-P1 where P1, { =INDEX(N:N,LARGE(IF(N:N<>"",ROW(N:N)),2)) } changes when data is entered into new/next row, I would like to copy this formula into multiple cells down column J, but to only have the formula calculate once. So when new a value is entered in i.e, N90, ONLY Cell J90 would calculate =SUM(N90)-P1 while the formulae in previous would cease to function - or maintain the original value.

    There are blanks in column N (hence the formula in P!). Thank you!

  2. #2
    Forum Expert
    Join Date
    05-01-2014
    Location
    California, US
    MS-Off Ver
    Excel 2010
    Posts
    1,795

    Re: Formula to only run once?

    You cannot do what you want. Either Excel evaluates all formulas whenever it feels the need to, or we can set it up so that it evaluates no formulas (in all worksheets or in specific worksheets) unless and until we tell it to, at which point Excel will evaluate all formulas as needed.

    The only way to avoid the all-or-none evaluation is to copy-and-paste-value after evaluation, which replaces the formula with the value. But after that, we cannot "recover" (re-enter) the formula easily.

    I suspect you are concerned about the effect that evaluating these formulas has on editing, saving and opening the workbook, etc.

    A major design flaw is the use of N:N in your formulas. INDEX(N:N,...) is okay. But IF(N:N...) causes Excel to create a temporary array of 1+ million rows (in Excel 2007 and later); and in this formula, it causes Excel to compare the value of 1+ million rows.

    Assuming that you have (much!) less than 1+ million rows of data in column N, it would be prudent to use a reasonable limited range -- as small as possible to improve performance, but as large as necessary to accommodate rows of data as they are added. (And sometimes, we can design the range so that it expands automagically after adding rows.) For example: IF($N$2:$N$10000<>"",ROW($N$2:$N$10000)) .

    That might be sufficient to fix the problem that you wanted to fix by evaluating formulas only one time.

    Aside.... Why are you writing SUM(N88) instead of just N88? If you want a function to return zero when N88 is text, consider using N(N88) instead. Technically, that would be more efficient; but admittedly, it is unlikely that we would notice the infinitesimal improvement. I bristle when I see the unnecessary use of SUM; like SUM(A1-A2), in which case SUM is completely useless. I hope you are not in the habit of doing that.

  3. #3
    Registered User
    Join Date
    09-07-2017
    Location
    Southfield, MI
    MS-Off Ver
    2016
    Posts
    5

    Re: Formula to only run once?

    I am with you about SUM, I just used that for he example - I try to never use anything unnecessary.
    Anyhow, I have zero lag in my sheet as is - using the P1 formula calculating the entire column. Isn't there any way to have a formula simply return the result as text and kill the formula? Like an auto F2,F9?

  4. #4
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,940

    Re: Formula to only run once?

    I think your only way is through VBA. Would you like me to move the thread for you?
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  5. #5
    Registered User
    Join Date
    09-07-2017
    Location
    Southfield, MI
    MS-Off Ver
    2016
    Posts
    5

    Re: Formula to only run once?

    Yes, sure! Whatever this solution requires, I am game. Thank you!

  6. #6
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,940

    Re: VBA: Formula to only run once?

    I've moved the thread for you. I suggest, while waiting for a response, you supply a small sample workbook that illustrates what you are trying to achieve.

  7. #7
    Registered User
    Join Date
    09-07-2017
    Location
    Southfield, MI
    MS-Off Ver
    2016
    Posts
    5

    Re: VBA: Formula to only run once?

    I will work on a graphic to upload, thank you. How do I find the new thread?

  8. #8
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,940

    Re: VBA: Formula to only run once?

    No, not a graphic - a workbook, please.

    Will you please attach a sample Excel workbook? We are not able to work with or manipulate a picture of one and nobody wants to have to recreate your data from scratch.

    1. Make sure that your sample data are REPRESENTATIVE of your real data. The use of unrepresentative data is very frustrating and can lead to long delays in reaching a solution.

    2. Make sure that your desired results are also shown (mock up the results manually).

    3. Make sure that all confidential data is removed or replaced with dummy data first (e.g. names, addresses, E-mails, etc.).

    4. Try to avoid using merged cells as they cause lots of problems.

    Unfortunately the attachment icon doesn't work at the moment, so to attach an Excel file you have to do the following: just before posting, scroll down to Go Advanced and then scroll down to Manage Attachments. Now follow the instructions at the top of that screen.

    Please pay particular attention to point 2 (above): without an idea of your intended outcomes, it is often very difficult to offer appropriate advice.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 3
    Last Post: 01-10-2019, 09:34 AM
  2. Replies: 5
    Last Post: 02-16-2018, 06:50 AM
  3. Replies: 8
    Last Post: 09-22-2017, 05:41 AM
  4. Excel formula bar to display the result of the formula , not the formula?
    By max_max in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-18-2016, 07:15 PM
  5. Replies: 11
    Last Post: 06-06-2014, 03:34 PM
  6. how to hide formula in formula box, view lookup result in formula box?
    By vengatvj in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 10-14-2013, 04:06 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1