+ Reply to Thread
Results 1 to 7 of 7

macro to sum each range individually within a single column

  1. #1
    Registered User
    Join Date
    01-15-2010
    Location
    Austin, Texas
    MS-Off Ver
    Excel 2007
    Posts
    1

    macro to sum each range individually within a single column

    I have ranges of numbers in column A separated by 2 blank rows. I would like to write a macro that places the sum of each range within the first blank cell above the range of numbers.

    For example, there are numerical values within the range A3:A6. I would like to have the sum of A3:A6 placed in A2.

    The reason I need the macro is because the ranges vary in length. Some ranges may be 1 row while others contain 50 or more rows. The total number of rows in this sheet is approximately 22,000 (this includes all of the blank rows). By the way, if there is only one row or data I would still like to have it's value placed in the first blank cell above.

    I am extremely new to writing macros and apparently lack the knowledge to complete this task without some expert help. If would appreciate any help that I can get.

    If there's an existing thread for such an issue please provide the link so that I can hopefully learn.

    Thanks,
    J

  2. #2
    Registered User
    Join Date
    01-12-2010
    Location
    London, England
    MS-Off Ver
    Excel 2003-7
    Posts
    23

    Re: macro to sum each range individually within a single column

    Why use a macro at all? If all your data is in col A, use =IF(ISBLANK(C12),C11,D12+C11) in col B and the total will magically appear above each subsection of data, albeit in col B, not A.

    EDIT: The formula assumes your first data entry is in column C, row 11. You have to adjust the references.

  3. #3
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: macro to sum each range individually within a single column

    Hello jferguson,

    Welcome to the Forum!

    This macro will sum the tables and place the sum above the table. Change the starting of "A3" to what your starting cell will be. Copy this code into a standard VBA module.
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  4. #4
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: macro to sum each range individually within a single column

    This should do what you want
    Please Login or Register  to view this content.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  5. #5
    Registered User
    Join Date
    12-27-2009
    Location
    Paris, France
    MS-Off Ver
    Excel 2003
    Posts
    64

    Re: macro to sum each range individually within a single column

    Hello,

    Another way to

    1) create a sheet named "test" and put the numbers in column "A"
    2) copy the following code in a standard module

    Please Login or Register  to view this content.

    Adapt any constants identified by # # #

    The results appear in a new sheet.

    Best regards.

  6. #6
    Registered User
    Join Date
    04-16-2010
    Location
    California
    MS-Off Ver
    Excel 2003
    Posts
    1

    Re: macro to sum each range individually within a single column

    Hello,
    This is a great forum. This is my first post. I saw the answer to the following thread

    http://www.excelforum.com/excel-prog...le-column.html

    I am interested in this answer, but I need the total a the bottom of each range that is summed up. Can anyone help me with this.

    Thanks,
    yodzak

  7. #7
    Registered User
    Join Date
    12-27-2009
    Location
    Paris, France
    MS-Off Ver
    Excel 2003
    Posts
    64

    Re: macro to sum each range individually within a single column

    Hello,

    Try this code

    Please Login or Register  to view this content.

    Best regards.

    PMO
    Patrick Morange

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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