+ Reply to Thread
Results 1 to 8 of 8

Adding parent row data to child row

  1. #1
    Registered User
    Join Date
    11-10-2017
    Location
    Boston, MA
    MS-Off Ver
    2016
    Posts
    13

    Adding parent row data to child row

    OK I have a dataset of payments info that shows payments made against invoiced services. The payment info is on one row (amount, date, check#), followed by the multiple line items describing each service the payment is paying for (subamount, PO#, invoice#, service description). Each item in parentheses separated by commas represents a column.Then the second payment info follows on a row, followed by the line item this second payment is paying for. Etc. So effectively the payment info is grouped together with its line items on opening of the spreadsheet. There is no pattern to how many line items exist under each payment. Could be one or many. However if you were to randomize the sorting of the rows, there would be no way to tell what line item belongs to what payment. So I was looking to automate adding payment info data to each line item. Is there a way to do this?

    So it looks something like:

    row1: payment1 info (amount, date, check#)
    row2: payment1 line item 1 (subamount, PO#, invoice#, service description)
    row3: payment1 line item 2 (subamount, PO#, invoice#, service description)
    row 4: payment1 line item 3 (subamount, PO#, invoice#, service description)
    ....repeat...
    row n+1: payment2 date (amount, date, check#)
    row n+2: payment2 line item 1 (subamount, PO#, invoice#, service description)
    row n+3: payment2 line item 2 (subamount, PO#, invoice#, service description)
    row n+4: payment2 line item 3 (subamount, PO#, invoice#, service description)
    ...etc...

    One minor point is that the payment info data is in separate columns from the line item info, except for the amount & subamounts which appear in the same column.

    What I would like to do is find a formula or macro to add at least the date and check# to each corresponding line item row.

    Would this have to be a macro?
    Last edited by firepitz; 11-12-2017 at 12:05 PM.

  2. #2
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,209

    Re: Adding parent row data to child row

    Attach a sample workbook (not image).

    Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate.

    Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.

  3. #3
    Registered User
    Join Date
    11-10-2017
    Location
    Boston, MA
    MS-Off Ver
    2016
    Posts
    13

    Re: Adding parent row data to child row

    example xls attached
    Attached Files Attached Files

  4. #4
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,151

    Re: Adding parent row data to child row

    Try, long but simply.
    Presupposition: constant headline in row 5, constant headline name = "Amount", data starts at 7th row, constant blank one-rows gaps between data blocks, everything is based on column 'F'.
    Attached Files Attached Files

  5. #5
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,209

    Re: Adding parent row data to child row

    Code here from post #4

    Please Login or Register  to view this content.
    Copy the Excel VBA code
    Select the workbook in which you want to store the Excel VBA code
    Press Alt+F11 to open the Visual Basic Editor
    Choose Insert > Module
    Edit > Paste the macro into the module that appeared
    Close the VBEditor
    Save your workbook (Excel 2007+ select a macro-enabled file format, like *.xlsm)
    [B][I]


    See attached: results in "BEFORE"
    Attached Files Attached Files
    Last edited by JohnTopley; 11-13-2017 at 03:50 AM.

  6. #6
    Registered User
    Join Date
    11-10-2017
    Location
    Boston, MA
    MS-Off Ver
    2016
    Posts
    13

    Re: Adding parent row data to child row

    Thanks everyone, however when I ran the macro on a larger file I got a "Runtime Error '9' Subscript out of range" error. I have included the file here but deleted some data to protect the privacy....
    Attached Files Attached Files

  7. #7
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,209

    Re: Adding parent row data to child row

    Change code to this

    strRng = Sheets("VendorHistoryReport").UsedRange.Columns("f:f").Address

    from

    strRng = Sheets("BEFORE").UsedRange.Columns("f:f").Address]
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    11-10-2017
    Location
    Boston, MA
    MS-Off Ver
    2016
    Posts
    13

    Re: Adding parent row data to child row

    Quote Originally Posted by JohnTopley View Post
    Change code to this

    strRng = Sheets("VendorHistoryReport").UsedRange.Columns("f:f").Address

    from

    strRng = Sheets("BEFORE").UsedRange.Columns("f:f").Address]
    You da man!

+ 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. Copy data fom parent file to child files with different layouts
    By Marloes in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-14-2014, 05:12 AM
  2. [SOLVED] Parent child relationships(working out parent item) for each item
    By grphillips in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 03-21-2013, 05:58 AM
  3. Parent Child Relationship
    By Automation Guru in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 01-02-2013, 04:48 AM
  4. Vba code for Parent child
    By ken4ward in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-06-2012, 06:04 AM
  5. Parent Child Macro
    By ckattookaran in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-06-2012, 11:50 AM
  6. Replies: 3
    Last Post: 07-09-2010, 02:54 PM
  7. [SOLVED] Sorting Parent Child
    By kcmtnbiker in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-30-2006, 09:00 PM

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