+ Reply to Thread
Results 1 to 5 of 5

Needing macro or VBA to add child subtotal rows to a spreadsheet containing data

  1. #1
    Registered User
    Join Date
    04-27-2022
    Location
    Houston, Texas
    MS-Off Ver
    Microsoft 365
    Posts
    3

    Needing macro or VBA to add child subtotal rows to a spreadsheet containing data

    Hello,

    I have a spreadsheet containing imported data (Sample Sheet 1) that I use to add individual costs in each cell to get a total cost for each item. This process gets cumbersome when several costs are added to the same cell. I would like to be able to easily add "child" and/or "grandchild" rows when I choose to do so in lieu of filling cells with multiple costs (sample Sheet 2).

    Is it possible to have a macro or VBA that can do the following?
    1. Quickly add an additional child and or grandchild row that contains formulas when I choose to add them.
    2. Have the parent row subtotal the child and/or grandchild values automatically, whether there be 1 or more child/grandchild rows, without having to change the subtotal formulas in the parent row.

    If any of you have a suggestion, it would be greatly appreciated! Thank you.
    Attached Files Attached Files

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Needing macro or VBA to add child subtotal rows to a spreadsheet containing data

    Hi and welcome to the forum.

    Have you considered the Data...Outline...Subtotal functionality.
    Or maybe a Pivot Table.

    Does the imported data come from a back office system over which you have control over what is output. It looks like your very much simplified example may be based on a .prn or .txt file layout.

    If you are able to get a normalised output of unique columns, e.g. Item No, Description, Cost Ref (i.e. Cost 1;Cost 2;..etc) and Cost then a Pivot Table is going to be your most efficient way of analysing the data.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Registered User
    Join Date
    04-27-2022
    Location
    Houston, Texas
    MS-Off Ver
    Microsoft 365
    Posts
    3

    Re: Needing macro or VBA to add child subtotal rows to a spreadsheet containing data

    Thank you Richard for the VERY fast reply. So the Data...Outline...Subtotal functionality works opposite of what I'm looking for. For my scenario, I first start with a list of items that I copy and paste into a worksheet. The items copied and pasted are item no.'s and random descriptions, for example. Then I add different costs (cost 1, 2, 3...) across the row to get a total cost for each item number. The example below shows columns A, B, C, and D as imported data. Columns E, F and G are costs that are either manually input, or contain vlookup formulas to help derive the cost.
    Attachment 778472

    What I am hoping for is to be able to create a macro or VBA that will insert either a child row, or grandchild row, under an existing item no. when i direct it to. The added child or grandchild rows would have nested formulas in them, and the parent row (and child row if using grandchild) would subtotal everything below it, regardless if there were 3 child rows added or 15 child/ grandchild rows. The example below shows 3 items (rows 2, 9 and 14) that would be expanded with child/ grandchild items.
    Attachment 778476

    Thanks again for your help.

  4. #4
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Needing macro or VBA to add child subtotal rows to a spreadsheet containing data

    So let me understand this

    In the original 4 row example you would position the cursor in A3 and add four rows in which you entered the 4 items 1.1, 1.2, 1.3 & 1.4
    You'd then want the macro to automatically add the totals to the Item 1 in row 2.

    Then you might put the cursor in A4 and add two new rows in which you added 1.1.1 & 1.1.2 with the 1.1 child item containing the total for the two grandchidren rows.

    How do you see this being controlled? I envisage with the cursor in a cell, starting the macro would prompt the user to add x no of rows, and choose at what level, i.e. the same level as the one above or the next sub level of the one above.

  5. #5
    Registered User
    Join Date
    04-27-2022
    Location
    Houston, Texas
    MS-Off Ver
    Microsoft 365
    Posts
    3

    Re: Needing macro or VBA to add child subtotal rows to a spreadsheet containing data

    That's right Richard. Using the original 4 row example, I would place the cursor in A3, start the macro, and be prompted to add x number of rows below row 3. The added rows would contain some cells having formulas, vlookups, etc. Also row 3 would then subtotal everything that was added below it with the macro.

+ 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. Novice with VBA and macro writing needing help to loop a macro unti no data
    By jrongone in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-25-2013, 12:19 PM
  2. [SOLVED] Multiple rows of horizontal data needing to arrange vertically (stacked)
    By jpeets645 in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 12-07-2012, 12:07 PM
  3. [SOLVED] Macro to sort data in spreadsheet but maintain empty rows between data.
    By vzc8 in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 06-12-2012, 12:31 AM
  4. Subtotal - Delete zero Subtotal and prior rows that calculate to that zero Subtotal
    By Whatsherface in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-14-2012, 08:37 PM
  5. Macro for modify the rows as Parent/child format
    By naflas in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-23-2010, 09:31 PM
  6. [SOLVED] Parent spreadsheet updating child spreadsheets
    By Art MacNeil in forum Excel General
    Replies: 0
    Last Post: 03-18-2005, 11:06 PM

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