+ Reply to Thread
Results 1 to 11 of 11

Help Transposing Large Amounts of Data

  1. #1
    Registered User
    Join Date
    11-30-2010
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    7

    Help Transposing Large Amounts of Data

    Hi, I'm new to all of this, but I've been having trouble finding any code or formulas out there to help out with this type of data specifically.

    I have data that as 872 columns - each representing a question ID (headers in the first row). I then have 1494 rows of data where each represents 1 unique person. In other words, A2 = Person ID and B2-AGN2=the potential answers to the questions.

    What I'd like to do is compact this into 3 columns: "Person ID", "Question", "Answer".

    "Person ID" will have duplicate values for each question that is answered.
    "Question" is the Question Text
    "Answer" is each answer to each of the questions.

    So in a condensed form, my data looks like this:

    ID Q1 Q2 Q3 QAge
    3 1 5 8 35
    4 1 2 12 64


    And I would like it to look like this:

    ID Question Answer
    3 Q1 1
    3 Q2 5
    3 Q3 8
    3 QAge 64
    4 Q1 1

    etc.

    It would be fantastic if Excel has the functionality to ignore null answers and therefore just not even bother populating Question ID when an Answer is blank (e.g. they didn't report an age, so QAge doesn't show up under the new "Question" field), but I have no idea if that's doable.


    I have a lot of datasets like this with a varied number of rows and columns, so it would be helpful if there was a way to adjust whatever formula/macro is out there to work for those. I'm terribly new with macros and so I've been having difficulty adapting them if I need to.


    I'm using Excel 2007.


    Any help you can offer would be greatly appreciated. Thanks!!!

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Help Transposing Large Amounts of Data

    Hello NFT86,

    Welcome to the Forum!

    This macro will copy and transpose the data using a separate sheet. The data is assumed to be on "Sheet1" with row 1 as the header row. The destination worksheet is "Sheet2". The header of ID, Question, and Answer is automatically added to the sheet. You can change the worksheet names to match your own worksheet names. They are marked in bold font in the code. Be sure you have enabled macros in your workbook.
    Please Login or Register  to view this content.

    Adding the Macro
    1. Copy the macro above 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. Paste the code by pressing the keys CTRL+V
    7. Make any custom changes to the macro if needed at this time.
    8. Save the Macro by pressing the keys CTRL+S
    9. Press the keys ALT+Q to exit the Editor, and return to Excel.

    To Run the Macro...
    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.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    11-30-2010
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Help Transposing Large Amounts of Data

    Thank you so much! It appears to be working really well, but then it runs into this runtime error: "Run-time error '1004': Application-defined or object-defined error". When I click debug, it highlights this line of code
    Please Login or Register  to view this content.

    I definitely am not savvy enough to read and edit this code, so maybe the error is something simple on my end (here's hoping). It looks like it really wants to work.


    Thank you so much for your help so far. I'll do what I can to try and fix it, but let me know if you can share some more of your wisdom!
    Last edited by Leith Ross; 12-01-2010 at 05:27 PM. Reason: Removed Quote and Added Code Tags

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Help Transposing Large Amounts of Data

    Hello NFT86,

    What did you change in the code?

  5. #5
    Registered User
    Join Date
    11-30-2010
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Help Transposing Large Amounts of Data

    I wasn't clear -- I didn't change anything in the code. It came up with that error the first time. I figured it might be something that had to do with my data or something simple I needed to adjust, but maybe not. I've tried deleting some of my columns from the raw data in case there's just too much, but I still get the error. Every now and then it highlights a different line in that same general block of code ('Copy and Transpose Data'), but I haven't had it run completely through yet regardless of how much data I get rid of.

    Thanks for replying again. Is there something else I should try or give to you to help?

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Help Transposing Large Amounts of Data

    Hello NFT86,

    I asked because in step 7 of the instructions, you should make changes to your macro. In this case the changes would be to the worksheet names. The macro is using the worksheets named "Sheet1" and "Sheet2". "Sheet1" contains the data you want to transpose. "Sheet2" is the worksheet where the condensed data will copied to. If the worksheet names in your workbook are different then you need to change the names in the macro to what you are using.

    Aside from that, you should not need to make any other changes to the macro. I tested the macro by creating a test workbook using the data provided in your first post. The macro successfully transposed and copied the data as shown in the post. If your actual workbook is arranged differently than this then that could be a potential problem.

  7. #7
    Registered User
    Join Date
    11-30-2010
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Help Transposing Large Amounts of Data

    Hi Leith,

    Thanks. I did change my worksheet names to be Sheet 1 and Sheet 2, respectively before I ran it the first time. Is there any chance there is just too much data? Like I said, I have 800+ columns of these various question IDs and then just under 1500 people with responses. Can Excel even handle transposing that to so many rows? It's upwards of over a million....It just seems to crash at that last block of code every time I run it.

    I really appreciate your help, but I understand if it's just not feasible.

    Thanks, and let me know what you think!

    NFT

  8. #8
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Help Transposing Large Amounts of Data

    Or ?

    Please Login or Register  to view this content.
    Last edited by snb; 12-03-2010 at 12:27 PM.



  9. #9
    Registered User
    Join Date
    11-30-2010
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Help Transposing Large Amounts of Data

    That code definitely informed me that I was being too ambitious. I got rid of a lot of the data, and I didn't get the message -- but I'm still getting an error in the original code when trying to transpose the data.

    Any ideas? Or should we just attribute this to me and my data? I really do appreciate all of the help!!

  10. #10
    Registered User
    Join Date
    07-05-2013
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Help Transposing Large Amounts of Data

    Thank you Lee and thank you nsb for the posting above.
    I am new to this forum and have never posted anything. I am not familiar with macros and I am faced with the task of having to handle the transposition of large amounts of data. My data set looks like this:
    Row 1 contains 111 columns (111 different titles) from A to DG
    Each row contains payroll information in relation to one unique employee.
    There are 3681 employees (3681 rows) excluding the title.

    The macro would transpose and rearrange the data in a similiar way as to that from NFT86 i.e.

    ID Question Answer (111 differently title colums)
    3 Q1 1
    3 Q2 5
    3 Q3 8
    3 QAge 64
    4 Q1

    I hope the above is clear.
    Any help will be greatly appreciated. thank you. Sal

  11. #11
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,938

    Re: Help Transposing Large Amounts of Data

    Hi and welcome to the forum Sal

    Unfortunately your post does not comply with Rule 2 of our Forum RULES. Do not post a question in the thread of another member -- start your own thread.

    If you feel an existing thread is particularly relevant to your need, provide a link to the other thread in your new thread.

    Old threads are often only monitored by the original participants. New threads not only open you up to all possible participants again, they typically get faster response, too.
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

+ 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