+ Reply to Thread
Results 1 to 21 of 21

Transpose and create duplicate names

  1. #1
    Forum Contributor
    Join Date
    03-16-2004
    MS-Off Ver
    2016
    Posts
    175

    Transpose and create duplicate names

    Excel 2007. Data is on sheet 1. Want a macro that goes down a list of names (over 100). There is only 1 unique name occurrence but data from multiple events are associated with that name in a horizontal manner. Want to copy name in R1C1 and data in R1C2...R1C10 to sheet 2, column R3C1,transpose, and create repetitive name associated with data. Then I want it to go to another range (in sheet 1) for the same name say R1C20...R1C30 and copy that data and transpose to sheet2 starting in R3C3.Then loop to end of name column. Example:

    dog.... 12 13 14 15 16 45 76.... oct nov dec jan feb march april
    cat.... 78 22 89 78 63.... oct nov dec jan feb
    Mouse.... 32.... oct

    Transposed to 3 separate columns

    dog 12 oct
    dog 13 nov
    dog 14 dec
    dog 15 jan
    dog 16 feb
    dog 45 march
    dog 76 april
    cat 78 oct
    cat 22 nov
    cat 89 dec
    cat 78 jan
    cat 63 feb
    mouse 32 oct
    Last edited by light; 11-03-2011 at 04:43 PM.

  2. #2
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591

    Re: Transpose and create duplicate names

    Hi

    see how this goes.
    Please Login or Register  to view this content.
    rylo

  3. #3
    Forum Contributor
    Join Date
    03-16-2004
    MS-Off Ver
    2016
    Posts
    175

    Re: Transpose and create duplicate names

    Thanks rylo but it came out like this with the parameters I gave:

    dog 12
    dog 13
    dog 14
    dog 15
    dog 16
    dog 45
    dog 76
    dog
    dog
    cat 78
    cat 22
    cat 89
    cat 78
    cat 63
    cat
    cat
    cat
    cat
    mouse 32
    mouse
    mouse
    mouse
    mouse
    mouse
    mouse
    mouse
    mouse


    It's not picking up the 3rd column and I don't want the name there if there is no data for it. Like in my example,there should only be one "mouse",five "cats" and seven "dogs". Also the offset part will not work because the sheet is actually 1500 columns wide and I was just giving an example.I need the macro to use the range.

  4. #4
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591

    Re: Transpose and create duplicate names

    Hi

    To avoid confusion on interpretation, put up an example file, and show how the example data should output.

    rylo

  5. #5
    Forum Contributor
    Join Date
    03-16-2004
    MS-Off Ver
    2016
    Posts
    175

    Re: Transpose and create duplicate names

    Rylo, here is the example. Scroll to the right on sheet 1 to see the data for column c. Desired output is in sheet 2.
    Attached Files Attached Files
    Last edited by light; 11-01-2011 at 11:02 PM.

  6. #6
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591

    Re: Transpose and create duplicate names

    Hi

    Here goes.

    Please Login or Register  to view this content.
    rylo

  7. #7
    Forum Contributor
    Join Date
    03-16-2004
    MS-Off Ver
    2016
    Posts
    175

    Re: Transpose and create duplicate names

    Thanks again rylo. That did work correctly. In actuality the data I want to retrieve is in columns 826...835 and in 846...855 with other data all around these ranges. What adjustments should I make to the code?

  8. #8
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591

    Re: Transpose and create duplicate names

    Hi

    Change
    Please Login or Register  to view this content.
    to be

    Please Login or Register  to view this content.
    rylo

  9. #9
    Forum Contributor
    Join Date
    03-16-2004
    MS-Off Ver
    2016
    Posts
    175

    Re: Transpose and create duplicate names

    Thanks again but am now getting a run time error 1004 after executing this line

    OutSh.Cells(outrow, 1).Resize(dataitems, 1).Value = ce

    Also in your changes you show two

    (outrow, 3)
    (outrow, 3)

    I assume the first should be (outrow, 2). Any rate tried both ways.

  10. #10
    Forum Contributor
    Join Date
    03-16-2004
    MS-Off Ver
    2016
    Posts
    175

    Re: Transpose and create duplicate names

    rylo

    I think I figured out why I get that error. Its because in the real sheet there are no empty cells to separate the data ranges. I inserted a space between the ranges and the code worked but the results are a little sketchy in that a lot of names only got partial info.

  11. #11
    Forum Contributor
    Join Date
    03-16-2004
    MS-Off Ver
    2016
    Posts
    175

    Re: Transpose and create duplicate names

    Here is what the real file looks like.
    Attached Files Attached Files

  12. #12
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591

    Re: Transpose and create duplicate names

    can't make any sense out of that file. Can you pick a couple of column A items, show the result for them and explain exactly where the data comes from in sheet1.

    rylo

  13. #13
    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: Transpose and create duplicate names

    Hhello llight,

    This macro will transpose an copy the information on "Sheet1" to "Sheet2" as you asked. It starts with cell "A1" on "Sheet1" and copy the data to "Sheet2" starting with cell "A3".
    Please Login or Register  to view this content.
    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!)

  14. #14
    Forum Contributor
    Join Date
    03-16-2004
    MS-Off Ver
    2016
    Posts
    175

    Re: Transpose and create duplicate names

    Leith, thanks for the effort but only the name column came out right. The rest was strange.

    rylo and Leith here is a sample of what the output should look like. As you know, the names are in the first column. Then as previously mentioned I am trying to get the data in columns 826:835 and in 846:855 transposed.
    Attached Files Attached Files

  15. #15
    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: Transpose and create duplicate names

    Hello Light,

    Here is a sample workbook using the examples you posted. If you have changed your settings or locations then the code will need to be changed to match.
    Attached Files Attached Files

  16. #16
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Transpose and create duplicate names

    Can I try too?
    Please Login or Register  to view this content.
    Attached Files Attached Files

  17. #17
    Forum Contributor
    Join Date
    03-16-2004
    MS-Off Ver
    2016
    Posts
    175

    Re: Transpose and create duplicate names

    nilem

    Hey, thanks a lot. That worked great. Only the output should be on sheet2. A question on your code. If I want to expand on it and create more columns of result from different ranges,(currently we have 3 columns of results) what part of your code should I change?

  18. #18
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Transpose and create duplicate names

    For example, add one column in the output array.
    The code will change that:
    Please Login or Register  to view this content.
    The array output to Sheet2 (which is placed a green arrow).
    If you want to add a lot of columns, you may need change the whole code.

  19. #19
    Forum Contributor
    Join Date
    03-16-2004
    MS-Off Ver
    2016
    Posts
    175

    Re: Transpose and create duplicate names

    Thanks nilem. That worked too. Up to how many additional columns do you think would be too many for the code.

  20. #20
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Transpose and create duplicate names

    You will see it for yourself, when code will run too long (more than 30 seconds, for example) or you'll get the message "Out of memory".

  21. #21
    Forum Contributor
    Join Date
    03-16-2004
    MS-Off Ver
    2016
    Posts
    175

    Re: Transpose and create duplicate names

    Thanks again nilem.

+ 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