+ Reply to Thread
Results 1 to 4 of 4

Formula to recalculate values based on one value becoming static?

Hybrid View

  1. #1
    Registered User
    Join Date
    09-15-2014
    Location
    Greenwood Village, Colorado
    MS-Off Ver
    2010
    Posts
    2

    Formula to recalculate values based on one value becoming static?

    I feel like this is such a simple thing, but for the life of me I can't figure out how to make this work. I have a formula that takes a figure and divides it out based on a certain # of periods. If one of those periods becomes a hard-coded figure, is there a way to have my formula automatically recalculate for the remaining periods? For example - expenditures for the year are $400,000, and this is broken out into 12, then 36 periods. Period 1-3 actuals come in, so I hard-code those figures in, but I need the remaining 30 periods plus 1-3 to still equal the $400K. Thanks in advance for the help!

  2. #2
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: Formula to recalculate values based on one value becoming static?

    This was a neat little project to learn how to write Functions.

    I created two User Defined Functions: one to Sum non-formula cells, and another to Count the number of formula cells.

    Then I used a formula: (TotalBudget-NotFormulaSum(range))/IsFormula(range)

    The result is that the running dispursement updates dynamically as hard-coded figures are entered manually over the existing formulas.


    Here's the quick and easy version of how to make this work for you:

    In Excel, hit Alt+F11

    Go to Insert->Module

    Paste the code below:

    Function IsFormula(rng As Range)
    
    Dim cells As Range, x As Long
    For Each cells In rng
    If cells.HasFormula Then x = x + 1
    Next
    IsFormula = x
    End Function
    
    Function NotFormulaSum(rng As Range)
    Dim cells As Range, x As Long
    For Each cells In rng
    If Not cells.HasFormula Then x = cells + x
    Next
    NotFormulaSum = x
    End Function
    Now close that window and use the new Functions as needed. Change "range" in my formula to whatever cells you need them to be.

    In the attached example, I made A2:A13 months, and B2:B13 the expenditures, with B14 being the $400,000.

    B2: =($B$14-NotFormulaSum($B$2:$B$13))/isformula($B$2:$B$13)

    and copied down
    Attached Files Attached Files
    Make Mom proud: Add to my reputation if I helped out!

    Make the Moderators happy: Mark the Thread as Solved if your question was answered!

  3. #3
    Registered User
    Join Date
    09-15-2014
    Location
    Greenwood Village, Colorado
    MS-Off Ver
    2010
    Posts
    2

    Re: Formula to recalculate values based on one value becoming static?

    Thank you so much daffodil11! That was just what I needed.

  4. #4
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: Formula to recalculate values based on one value becoming static?

    Awesome. I learned so much doing it too!

    Now I know that if I really want to annoy my boss, I can add:

    Function NUMBER_SMASH(rng As Range)
    
    Dim cells As Range, x As Double
    
    For Each cells In rng
        x = cells + x
    Next cells
    
    NUMBERSMASH = x
    
    End Function
    It works exactly the same as SUM, but instead it's called NUMBER_SMASH. Because I had too much sugar.

    The possibilities..

+ 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. [SOLVED] Recalculate values on scale from 1-7
    By oreganoca in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 09-03-2013, 05:07 PM
  2. recalculate formula in field based on what results are displayed
    By blackspiral in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-30-2013, 12:27 PM
  3. Recalculate Averages based on dates
    By herghost in forum Excel General
    Replies: 0
    Last Post: 08-03-2011, 02:58 PM
  4. Any way to have values on a separate tab recalculate?
    By mikeyt354 in forum Excel General
    Replies: 0
    Last Post: 03-09-2010, 12:14 PM
  5. Recalculate based on new row of data
    By s.ross in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-21-2009, 10:29 AM

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