+ Reply to Thread
Results 1 to 9 of 9

Accumulating total if Target cell contains formula

  1. #1
    Registered User
    Join Date
    06-21-2012
    Location
    East london
    MS-Off Ver
    Excel 2010
    Posts
    17

    Accumulating total if Target cell contains formula

    Good day,

    I need some help please? I need to accumulate the value of a cell (I39)from the value of another cell (G31) every time it changes and the code below does the trick,but only if the target cell is a manual input. How do I change it to work same for when the target cell (G31) contains a formula (=SUMG1;G30).

    Please help me?

    Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address = ["$G$31"] Then
    [I39] = [I39] + [G31]
    End If
    End Sub

  2. #2
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: Accumulating total if Target cell contains formula

    Instead of worksheet change, use:

    Please Login or Register  to view this content.
    Last edited by JasperD; 09-03-2015 at 03:49 PM.
    Please click the * below if this helps

  3. #3
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: Accumulating total if Target cell contains formula

    If G1:G30 as entered manually you could try this:

    Please Login or Register  to view this content.
    Click the * Add Reputation button in the lower left hand corner of this post to say thanks.

    Don't forget to mark this thread SOLVED by going to the "Thread Tools" drop down list above your first post and choosing solved.

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,422

    Re: Accumulating total if Target cell contains formula

    Maybe:

    Please Login or Register  to view this content.

    Regards, TMS


    Edit: Added
    Please Login or Register  to view this content.
    Last edited by TMS; 09-03-2015 at 05:59 PM. Reason: Added [CODE]On Error GoTo 0[/CODE]
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,422

    Re: Accumulating total if Target cell contains formula

    @Skywriter: thanks for the rep.

    Note that .precedents only works if the cells precedents are on the same worksheet. If the precedents were on another worksheet, you'd need a Change event handler on that sheet which then checked the outcome on the sheet with the dependent cell (hope that makes sense).

  6. #6
    Registered User
    Join Date
    06-21-2012
    Location
    East london
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Accumulating total if Target cell contains formula

    Hi JasperD,

    Thank you for your assistance. Your code works well, but if the next or updated sheet contains the same values, ie, same sales for two days, then I39 won't add the new (although same) value. Hope I make sense, and hope you can assist?

    Blessings

  7. #7
    Registered User
    Join Date
    06-21-2012
    Location
    East london
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Accumulating total if Target cell contains formula

    Hi TMS,

    Thanks for the code, it works great, but it keeps adding the first value also. IE, if first value was 20 and the next to add was 10 then I'd get accumulated value of 50 instead of 30? Can you fix that? Thanks for your help!

  8. #8
    Registered User
    Join Date
    06-21-2012
    Location
    East london
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Accumulating total if Target cell contains formula

    Hi Skywriter,

    Thanks for your help. The values in G1;G30 are a result of other formulas, but thank you for your help!

    Blessings

  9. #9
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,422

    Re: Accumulating total if Target cell contains formula

    The code was intended to demonstrate a couple of options. You need to comment out the one you don't want.

    Maybe this will clarify:

    Please Login or Register  to view this content.
    If this doesn't resolve the issue, you probably need to give a few examples of what you expect to see. For example, assuming I39 starts at 0 (or blank) and G31 contains the formula: =SUM(G1:G30) then: G1=1, G31=1, I39=1; G2=2, G31=3, I39=4; G3=3, G31=6, I39=10; ... etc


    See the example workbook.


    Regards, TMS
    Attached Files Attached Files

+ 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. Sum numbers and change cell color each time a target total is reached
    By mike3029 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-18-2014, 02:08 AM
  2. [SOLVED] Formula which calculates total against a changing month to date target
    By Glayva in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 05-09-2014, 07:43 AM
  3. Creating a formula for accumulating interest
    By JacobA in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 02-16-2013, 06:29 PM
  4. Replies: 5
    Last Post: 01-22-2013, 11:38 AM
  5. Worksheet_CHange (ByVal Target as Range) when target is formula cell
    By coasterman in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-09-2012, 07:00 PM
  6. accumulating total
    By exhausted everything in forum Excel General
    Replies: 1
    Last Post: 03-14-2006, 08:30 PM
  7. Replies: 0
    Last Post: 06-14-2005, 12:13 PM

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