+ Reply to Thread
Results 1 to 11 of 11

Help transforming N Columns to M with a twist...

  1. #1
    Registered User
    Join Date
    06-27-2012
    Location
    Portugal
    MS-Off Ver
    Excel 2011
    Posts
    11

    Help transforming N Columns to M with a twist...

    Hi,

    For the past few days I've been trying to solve a problem that, now, I recognize to be well beyond my ability....
    I've searched the forum for solutions...and I couldn't find anything that solved my problem.

    So, I have a bunch of data data organized in N columns. The first few columns (call it X columns), contain reference data and the last few (call it Y columns) have answers to a survey (they are all numeric scores).

    If I identifiy the Y columns as Y(1), Y(2), Y(3)...Y(n)
    I need to reorganize this table to get:
    The first X columns (reference data)+ 1 column containing the label of Y(0) in all rows + 1 column containg the values of Y(0)
    Repeat and append data in the same format for Y(1)...Y(N).

    I'm attaching an example to make this clear.
    example.xlsx

    If anyone could help me with a macro that does this or point to somewhere where I can find it, I would be forever grateful as I'm facing quite a daunting task if I'm going to do this by hand...

    Thanks a lot for your time and attention.
    miguel

  2. #2
    Forum Contributor bonny24tycoon's Avatar
    Join Date
    04-02-2012
    Location
    Hell
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    405

    Re: Help transforming N Columns to M with a twist...

    Hi there,

    So would the real data also have 4 X's and 4 Y's?? Also would it always have 6 lines of survey for ID1's??
    Thanks,

    Bonny Tycoon


  3. #3
    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: Help transforming N Columns to M with a twist...

    Hi,

    See the attached which uses the following macro.

    Please Login or Register  to view this content.
    Attached Files Attached Files
    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.

  4. #4
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Help transforming N Columns to M with a twist...

    option, press "Run" button
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    06-27-2012
    Location
    Portugal
    MS-Off Ver
    Excel 2011
    Posts
    11

    Re: Help transforming N Columns to M with a twist...

    Quote Originally Posted by bonny24tycoon View Post
    Hi there,

    So would the real data also have 4 X's and 4 Y's?? Also would it always have 6 lines of survey for ID1's??
    Hi,

    Thanks for your reply...This was just an example.
    I hope then I'm able to change the code to the real number..

    cheers,
    Miguel

  6. #6
    Registered User
    Join Date
    06-27-2012
    Location
    Portugal
    MS-Off Ver
    Excel 2011
    Posts
    11

    Re: Help transforming N Columns to M with a twist...

    Quote Originally Posted by Richard Buttrey View Post
    Hi,

    See the attached which uses the following macro.
    Hi Richard,

    Thanks a lot!
    This is exctly what i need!

    I've tested it with more "Score" columns and it also works!

    I would only ask you where do I need to change if I want to add more "X columns" (reference data).
    I'm trying to figure it out...but my programming abilities are low and I don't want to break it.

    thanks a lot!

    miguel

  7. #7
    Registered User
    Join Date
    06-27-2012
    Location
    Portugal
    MS-Off Ver
    Excel 2011
    Posts
    11

    Re: Help transforming N Columns to M with a twist...

    Hi Watersev,

    Thanks a lot!

    it also works great.

    I would also have the same question as for richard, where can I change it when I have mopre columns "X" (reference data)?

    thanks again!

    miguel

  8. #8
    Registered User
    Join Date
    06-27-2012
    Location
    Portugal
    MS-Off Ver
    Excel 2011
    Posts
    11

    Re: Help transforming N Columns to M with a twist...

    Hi Watersev,

    Thanks a lot!

    it also works great.

    I would also have the same question as for richard, where can I change it when I have mopre columns "X" (reference data)?

    thanks again!

    miguel

  9. #9
    Registered User
    Join Date
    06-27-2012
    Location
    Portugal
    MS-Off Ver
    Excel 2011
    Posts
    11

    Re: Help transforming N Columns to M with a twist...

    Quote Originally Posted by tonelot View Post
    Hi Richard,

    Thanks a lot!
    This is exctly what i need!

    I've tested it with more "Score" columns and it also works!

    I would only ask you where do I need to change if I want to add more "X columns" (reference data).
    I'm trying to figure it out...but my programming abilities are low and I don't want to break it.

    thanks a lot!

    miguel
    Hi Richard,

    I Was trying to change the number of "X" columns...but it seems that that number is hardcoded in a few places and it's breaking.
    Wouldn't it be possible to define a variable in the beginning of the macro that would hold the number of columns with reference data an then this would be used in the code?

    cheers
    miguel

  10. #10
    Registered User
    Join Date
    06-27-2012
    Location
    Portugal
    MS-Off Ver
    Excel 2011
    Posts
    11

    Re: Help transforming N Columns to M with a twist...

    Quote Originally Posted by watersev View Post
    option, press "Run" button
    Hi watersev,

    Actually I've been able to modify your macro to have a variable handling a differente number of coumns.
    and it seems to work!

    Now I just have a problem with the column headers being harcoded in the macro, as I have several files to treat and they don't hold all the same columns. (this data from an internal survey).

    is tehere a way to make the macro grab the column headers dynamic?
    My alternative is to copy the macro for as many versions as I have to treat...which is kind of risky.

    Thanks a lot for your help.

    cheers,
    miguel

  11. #11
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Help transforming N Columns to M with a twist...

    hi miguel, the code must have some logic to put in for it to work with different files and column headers. In your posted file the logic for headers was: take four column headers plus two new columns. As soon as you can explain the logic for the other file options we can think how to incorporate it into the code.

    If 4 first columns will be still taken to a result table but may have different names, this option would work
    Attached Files Attached Files
    Last edited by watersev; 06-28-2012 at 09:19 AM.

+ 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