+ Reply to Thread
Results 1 to 6 of 6

Sum in a macro

  1. #1
    Registered User
    Join Date
    03-01-2009
    Location
    Woodmere, New York
    MS-Off Ver
    Excel 2007
    Posts
    31

    Sum in a macro

    Hi Guys,

    I have a Macro and I would like sum one column after the last cell with a value in it. This cell has variable length with each file.

    Is ther a way to include this function in my existing Macro?
    Last edited by tallguy6354; 04-07-2009 at 01:07 PM.

  2. #2
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988

    Re: Sum in a macro

    Maybe like

    Please Login or Register  to view this content.
    VBA Noob
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  3. #3
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Sum in a macro

    Or if going the "other way" - ie Sum row in column after last cell

    Please Login or Register  to view this content.
    the above is based on row 1, alter as required (if required)

  4. #4
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243

    Re: Sum in a macro

    hi Tallguy,

    The others have provided two working solutions for your question, however, I'll throw a question & some comments back for you to consider w.r.t. spreadsheet design...

    Are you open to modifying your worksheet layout?
    If so, I suggest...
    - Inserting (if necessary) an extra row above the column headers on your spreadsheet & placing the equation in the cell on this row.
    - Then using Freeze Panes to ensure that the headers & this equation cell are always visible.
    - Changing from a Sum formula to a "=Subtotal(9,..." formula if you are using Autofilter on the sheet because the Subtotal version will only total the visible rows.

    Advantages of the above aproach include:
    -The total is always visible at the top.
    -It allows for easy comparison of files because the total is always in the same cell (you can also "name the cell" to allow quicker formula entry that rely on the total.

    Please Login or Register  to view this content.

    hth
    Rob
    Rob Brockett
    Kiwi in the UK
    Always learning & the best way to learn is to experience...

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Sum in a macro

    - Inserting (if necessary) an extra row above the column headers on your spreadsheet & placing the equation in the cell on this row.
    ...
    -The total is always visible at the top.
    A very good suggestion, IMO. Excel 'prefers' that formulas reference data to the left and above, but this make sheets much easier to read, and in many cases, design.
    Entia non sunt multiplicanda sine necessitate

  6. #6
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243

    Re: Sum in a macro

    Thanks Shg :-)

    Yes, this situation is one of the few times I break the principle of "reference data to the left and above" but I justify it to myself by the fact that about a dozen is probably the absolute max' total cells that I would have at the top of a sheet (usually only 1 to 3 cells). I think the pro's of ease of use + future design/development probably outweigh the small (?) negative impact from this number of cells on the calculation dependency tree.

    Rob

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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