+ Reply to Thread
Results 1 to 6 of 6

Inserting and summing rows

  1. #1
    Registered User
    Join Date
    11-30-2010
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    3

    Inserting and summing rows

    Hi.

    I have a list in column D. List is sorted, so all data is grouped.

    I am trying to insert a blank row after each group

    Example:
    103
    103
    107
    109
    109
    109
    109
    Needs to be…
    103
    103

    107

    109
    109
    109
    109

    Then, I want to add a subtotal for each group, but in columns R, S, and T instead of column D. I will be summing the data that is in column R for each group, column S for each group, and column T for each group. Column D is only used to sort and space the groups.

    Thanks for any help!

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

    Re: Inserting and summing rows

    kortni,

    Please attach your workbook or a sample workbook that accurately portrays your current workbook on one sheet, and what it should look like 'After' on another sheet.

    This makes it much easier to see exactly what you want to do, as well as shows us whether there is a consistent number of rows between tables and such.

    To attach the workbook click on the New Post button, then scroll down and click on the Manage Attachments button.
    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
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,896

    Re: Inserting and summing rows

    Use the excel built in sub total function. Depending on the version of Excel, it can be found under DATA.

    Alan
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  4. #4
    Registered User
    Join Date
    11-30-2010
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Inserting and summing rows

    Thank you Stan and Alan.

    Alan, I was looking to do both tasks in one step, but using the subtotal feature works just fine.

    I used this code to separate the groups:

    Sub process()
    Dim Lastrow As Long
    Dim i As Long

    Application.ScreenUpdating = False

    With ActiveSheet

    Lastrow = .Cells(.Rows.Count, "D").End(xlUp).Row
    For i = Lastrow - 1 To 1 Step -1

    If Cells(i, "D").Value2 <> Cells(i + 1, "D").Value2 Then

    .Rows(i + 1).Insert
    End If
    Next i
    End With

    Application.ScreenUpdating = True
    End Sub

    and then used the subtotal feature to get my subtotals.

    Thanks again for your help!

  5. #5
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,896

    Re: Inserting and summing rows

    If you use the subtotal wizard, then it will automatically separate the sections for you and add a grouping feature and you do not need to use VBA. It does only do one sub total and you would have to copy the formula over for the other subtotals, however.

    Alan

  6. #6
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Inserting and summing rows

    Hi kortni

    Here's the code to do what you require with VBA
    Please Login or Register  to view this content.
    I should point out, you will need to change this line of code to reflect your worksheet structure
    Please Login or Register  to view this content.
    John
    Last edited by jaslake; 11-30-2010 at 05:09 PM.
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

+ 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