+ Reply to Thread
Results 1 to 7 of 7

Macro to SUM the cells between two blank cells in a column, multiple occurances

  1. #1
    Registered User
    Join Date
    05-06-2013
    Location
    San Diego
    MS-Off Ver
    Excel 2003
    Posts
    10

    Macro to SUM the cells between two blank cells in a column, multiple occurances

    I have a single column of numbers (varying length) with blank cells randomly spaced. How can I select cells between two blank cells. For example if I have this:

    1
    1
    3
    2
    7
    1
    2
    2
    5

    I want to be able to add the numbers between the blank cells. Basically end up with a sheet like this after the macro is initiated, the sum of the groups being in the next column over:

    1
    1
    3
    2 7
    7
    1
    2 10
    2
    5 7
    Last edited by importriders; 06-28-2013 at 12:13 PM.

  2. #2
    Forum Expert
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    2,387

    Re: Macro to SUM the cells between two blank cells in a column, multiple occurances

    importriders

    With your raw data, numbers, beginning in cell A1.

    Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

    1. Copy the below code, by highlighting the code and pressing the keys CTRL + C
    2. Open your workbook
    3. Press the keys ALT + F11 to open the Visual Basic Editor
    4. Press the keys ALT + I to activate the Insert menu
    5. Press M to insert a Standard Module
    6. Where the cursor is flashing, paste the code by pressing the keys CTRL + V
    7. Press the keys ALT + Q to exit the Editor, and return to Excel
    8. To run the macro from Excel, open the workbook, and press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.

    Please Login or Register  to view this content.
    Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm

    Then run the SumAreas macro.
    Have a great day,
    Stan

    Windows 10, Excel 2007, on a PC.

    If you are satisfied with the solution(s) provided, please mark your thread as Solved by clicking EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

  3. #3
    Registered User
    Join Date
    05-06-2013
    Location
    San Diego
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: Macro to SUM the cells between two blank cells in a column, multiple occurances

    Works like a champ. Thank you soo much.

  4. #4
    Forum Expert
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    2,387

    Re: Macro to SUM the cells between two blank cells in a column, multiple occurances

    importriders,

    Thanks for the feedback.

    You are very welcome. Glad I could help.

    And, come back anytime.

  5. #5
    Valued Forum Contributor
    Join Date
    03-21-2013
    Location
    cyberia
    MS-Off Ver
    Excel 2007
    Posts
    457

    Re: Macro to SUM the cells between two blank cells in a column, multiple occurances

    just 4 interest
    {code}
    For Each a In Range("A:A").SpecialCells(2).Areas
    a(a.Count)(1, 2) = "=sum(" & a.Address & ")"
    Next

    {/code}

  6. #6
    Registered User
    Join Date
    12-10-2013
    Location
    Columbia, SC
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Macro to SUM the cells between two blank cells in a column, multiple occurances

    Hi Stan, I tried out this macro (to sum cells between blanks) and it does work really great.
    Do you have a version that will ignore zeroes and sum values from formulas? that would be a lifesaver!
    Thanks in advance!

  7. #7
    Forum Expert
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    2,387

    Re: Macro to SUM the cells between two blank cells in a column, multiple occurances

    C.L.Garthwaite,

    Welcome to the Excel Forum.

    I assume that your dataset is different - contains formulae.

    Please do not post your questions in threads started by others - - this is known as thread hijacking.

    Always start a new thread for your questions and, if you think it helps, provide a link to any other thread as a reference.

    Start a new thread for your question:
    1. be sure to give it a search friendly title that accurately describes your need.
    2. To get the most precise answer, it is best to upload/attach a sample workbook (sensitive data scrubbed/removed/changed) that contains an example of your raw data on one worksheet, and on another worksheet your desired results.

    The structure and data types of the sample workbook must exactly duplicate the real workbook. Include a clear and explicit explanation of your requirements.

    To attach your workbook, scroll down and click on the Go Advanced button, then scroll down and click on the Manage Attachments button.

    3. Then send me a Private Message, with a link to your NEW thread, and, I will have a look.
    Last edited by stanleydgromjr; 12-28-2013 at 08:53 AM.

+ 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