+ Reply to Thread
Results 1 to 7 of 7

Need to reorg table so new table is row1= col1, col2,n1,col3,row2=col1,col2,n2,col4

  1. #1
    Registered User
    Join Date
    08-19-2012
    Location
    Houston, TX USA
    MS-Off Ver
    Excel 2010
    Posts
    2

    Need to reorg table so new table is row1= col1, col2,n1,col3,row2=col1,col2,n2,col4

    I have a data set with 5 columns. The first 2 columns are identifiers and the last 3 columns are properties. I need to convert the data so that I have 2 identifiers on each row. Then I want to put the name of each property on one row along with the value of that property. So along with the name of column 3 as column 3 and value of column 4 as column 4. The next row of data will be the first 2 columns of the data set plus the name of column 4 as column 3 and the value of column 4 as column 4.
    Example data:

    What I have is:

    FirstName LastName Height Weight HairColor
    Bob Smith 6'0" 200 Brown
    Mary Jones 5'6" 120 Blond

    What I need is:

    FirstName LastName PropertyName PropertyValue
    Bob Smith Height 6'0"
    Bob Smith Weight 200
    Bob Smith HairColor Brown
    Mary Jones Height 5'6"
    Mary Jones Weight 120
    Mary Jones HairColor Blond

    Does anyone have any ideas on how to do this? Many thanks for your help. My actual files might have 4 - 6 columns of identifiers, up to 100 rows of properties and hundreds or thousands of rows of data so this is not a trivial conversion.
    Attached Images Attached Images
    Last edited by Brantly; 08-19-2012 at 11:48 PM. Reason: Solved

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

    Re: Need to reorg table so new table is row1= col1, col2,n1,col3,row2=col1,col2,n2,col4

    Brantly,

    Welcome to the Excel Forum.


    Detach/open workbook ReorgData w1 wR - Brantly - EF853973 - SDG15.xlsm and run the ReorgData macro.



    If you want to use the macro on another workbook:


    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 ReorgData 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
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Need to reorg table so new table is row1= col1, col2,n1,col3,row2=col1,col2,n2,col4

    Try the attached
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    08-19-2012
    Location
    Houston, TX USA
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: Need to reorg table so new table is row1= col1, col2,n1,col3,row2=col1,col2,n2,col4

    Stanleydgromjr and jindon,

    Thank you very much for the wonderful responses. Both of them did exactly what I wanted them to do. My followup question is how I edit the macros if I have 6 key columns and 12 data columns (since I am not sure what format the files will be coming in with). I do appreciate the efforts that both of you put in. You are both great.

  5. #5
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Need to reorg table so new table is row1= col1, col2,n1,col3,row2=col1,col2,n2,col4

    Not tested
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    08-17-2012
    Location
    Indianapolis, IN
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Need to reorg table so new table is row1= col1, col2,n1,col3,row2=col1,col2,n2,col4

    I have a similar problem that I am trying to solve.

    My data has a reference number in column 1 and then 6 columns of data related to one issue, 6 columns of data related to a second issue, and 6 columns related to a third issue. I need to have the reference number remain in column 1 and then the issues related items all in the next 6 columns, one issue under the other.

    I have attached an excel file with code that gets me pretty close but I can't seem to get all the way there..Help!!
    Attached Files Attached Files

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

    Re: Need to reorg table so new table is row1= col1, col2,n1,col3,row2=col1,col2,n2,col4

    melliesue,

    Your workbook data structure is not similar to the original post by Brantly.

    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 and be sure to give it a search friendly title that accurately describes your need.

    And, please manually complete another worksheet with the results you are looking for.

+ 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