+ Reply to Thread
Results 1 to 9 of 9

Combine two rows of data into one row

  1. #1
    Registered User
    Join Date
    01-10-2010
    Location
    Australia
    MS-Off Ver
    Excel 2003
    Posts
    29

    Combine two rows of data into one row

    Hi Everyone,

    My colleague has a data extract that has information belonging to one customer over two rows. What we would like to do is bring each set together so that for each customer there is only one row. I have googled and searched the forum and the closest thing to this I can find is splitting one row into two using the "OFFSET" function.

    This report is recieved weekly and will end up with around 5000 entries so a solution with as little manual input as possible would be much appreciated!

    Let me know if you require a sample

    Thanks

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Combine two rows of data into one row

    This can be done rather easily with a macro. Is VBA OK?

    If so, provide a workbook showing two BEFORE and AFTER sheets on a small set of the data. Don't dumb it down too much, or a macro written based on your example sheets won't work.

    Click GO ADVANCED and use the paperclip icon to post up a desensitized copy of your workbook.
    Last edited by JBeaucaire; 10-01-2010 at 10:07 AM.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    01-10-2010
    Location
    Australia
    MS-Off Ver
    Excel 2003
    Posts
    29

    Re: Combine two rows of data into one row

    More Info: There is no unique identifier in both rows

  4. #4
    Registered User
    Join Date
    01-10-2010
    Location
    Australia
    MS-Off Ver
    Excel 2003
    Posts
    29

    Re: Combine two rows of data into one row

    I have attached a sample of the steps we go through starting from what we get in a text file and finishing with the ideal end result. It's perfectly fine if the solution can only match the "move to one line" tab, but the "end result" is preferred if that can be automated too (it's just concatinating the related fields to tidy it up). The data will always be the same size and shape.

    Thanks for your help!
    Attached Files Attached Files

  5. #5
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Combine two rows of data into one row

    It's interesting that you don't want to put the time back together properly. On the End Result sheet the content in cell C1 is 6AM but there is a PM in D1. Wouldn't that be best if C1 and D1 were merged properly back into a single cell with the correct time in it?

    Anyway, I wrote a custom function for this task so you can use it the same way. Here's the function:
    Please Login or Register  to view this content.

    On the attached sheet, I show how I'm using the function to directly parse the words out into the cells. Most only parse 1 word, but the function parses up to 4 words in a single cell.

    Then I wrote a simple macro to enter those formulas for you to parse the data, flatten the values, then remove the original column A. Run this on a copy of your data.

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by JBeaucaire; 10-11-2010 at 05:53 PM.

  6. #6
    Registered User
    Join Date
    01-10-2010
    Location
    Australia
    MS-Off Ver
    Excel 2003
    Posts
    29

    Re: Combine two rows of data into one row

    Hi Again,

    Thanks for the code

    I get a runtime error "Method 'Range' of object '_Global' failed, and the debugger points to:

    Range("B1:B" & LR / 2).FormulaR1C1 = "=WORD(INDEX(C1,ROW()*2-1), 1)"

    Any idea how to fix this?

  7. #7
    Forum Contributor Charlie_Howell's Avatar
    Join Date
    09-27-2010
    Location
    Memphis, TN
    MS-Off Ver
    Excel 2007
    Posts
    218

    Re: Combine two rows of data into one row

    If macros aren't an option try this
    Attached Files Attached Files

  8. #8
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Combine two rows of data into one row

    Quote Originally Posted by JoeyGirl View Post
    I get a runtime error "Method 'Range' of object '_Global' failed, and the debugger points to:
    Please Login or Register  to view this content.
    Any idea how to fix this?
    When you DEBUG at that moment and hover your cursor over LR, what is the value?

    If you need to edit the LR code at that top to use a different column, do so.

  9. #9
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Combine two rows of data into one row

    As a result of helping another OP with this same kind of need and the prompting of DonKeyOte, I've improved the WORD() function to be cleaner and unlimited in number of words it can pull out.

    Review the file and code in post #5 anew or the updates.

+ 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