+ Reply to Thread
Results 1 to 35 of 35

Transpose Varying Colums

  1. #1
    Registered User
    Join Date
    02-22-2022
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    18

    Transpose Varying Colums

    Hi all, I'm a basic VBAer but this one has me stumped. I basically have a single column of data that I wish to convert to multiple columns.
    Any assistance would be greatly appreciated.
    Thank you.


    From this (1 Column):

    Race #13289347
    Class*1
    3500m
    23/02/2022 10:32
    3rd
    26
    Race #13288620
    Class*1
    3500m
    23/02/2022 10:30
    11th
    Race #13287919
    Class*1
    3500m
    23/02/2022 10:28
    3rd
    26
    Race #13286369
    Class*1
    4000m
    23/02/2022 10:23
    6th
    Race #13283093
    Class*1
    3500m
    23/02/2022 10:10
    11th
    Race #13281097
    Class*1
    4000m
    23/02/2022 10:03
    6th
    Race #13260386
    Class*1
    3500m
    23/02/2022 8:32
    2nd
    44


    To this (6 Columns):

    Race #13289347 | Class*1 | 3500m | 23/02/2022 10:32 | 3rd | 26
    Race #13260386 | Class*1 | 3500m | 23/02/2022 8:32 | 2nd | 44
    Race #13281097 | Class*1 | 4000m | 23/02/2022 10:03 | 6th |
    Race #13283093 | Class*1 | 3500m | 23/02/2022 10:10 | 11th |
    Race #13286369 | Class*1 | 4000m | 23/02/2022 10:23 | 6th |
    Race #13287919 | Class*1 | 3500m | 23/02/2022 10:28 | 3rd | 26
    Race #13288620 | Class*1 | 3500m | 23/02/2022 10:30 | 11th |

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

    Re: Transpose Varying Colums

    Try
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    02-22-2022
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    18

    Re: Transpose Varying Colums

    Amazing!! This worked perfectly! (sorry for sounding surprised :D).

    Thank you some much!! Very, very much appreciated.
    Last edited by TravNoob; 02-23-2022 at 12:58 AM.

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

    Re: Transpose Varying Colums

    You are welcome.

  5. #5
    Registered User
    Join Date
    02-22-2022
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    18

    Re: Transpose Varying Colums

    I've realised this this actually swaps the Day and Month in the date. I've traced through the code and found that it transposes correctly but when it runs the TextToColumns it swaps the date and month. Any help is greatly appreciated. Thanks.


    From:
    Race #20863804
    Class*1
    3500m
    10/03/2022 11:09
    1st
    105

    To:
    Race #20863804 Class*1 3500m 3/10/2022 11:09 1st 105

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

    Re: Transpose Varying Colums

    Try change bold line if this does not work as you expected.
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    02-22-2022
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    18

    Re: Transpose Varying Colums

    Perfect! Thank you so so so much again.

  8. #8
    Registered User
    Join Date
    02-22-2022
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    18

    Re: Transpose Varying Colums

    While this works for double digit dates, it doesn't for single digits.

    Eg.
    From (is currently correct for me 7/03/2022 (7th March):
    Race #19240886
    Class*1
    3500m
    7/03/2022 9:00
    1st
    105

    To:
    Race #19240886 Class*1 3500m 3/07/2022 9:00 1st 105


    Sorry to keep asking for help. I have seriously tried Google and trial and error to fix this myself but I just don't have the skills (yet!).

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

    Re: Transpose Varying Colums

    Quote Originally Posted by TravNoob View Post
    Race #13260386
    Class*1
    3500m
    23/02/2022 8:32
    2nd
    44


    To this (6 Columns):

    Race #13288620 | Class*1 | 3500m | 23/02/2022 10:30 | 11th |
    Quote Originally Posted by TravNoob View Post
    From (is currently correct for me 7/03/2022 (7th March):
    Race #19240886
    Class*1
    3500m
    7/03/2022 9:00
    1st
    105

    To:
    Race #19240886 Class*1 3500m 3/07/2022 9:00 1st 105
    Confusing...

  10. #10
    Registered User
    Join Date
    02-22-2022
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    18

    Re: Transpose Varying Colums

    Are you saying that my threads are confusing? Sorry about that.

    The first one in your reply was an example of what I want to happen and the second example is what your script does. Your script works fine for double digit dates say '23/02/2022' but not for single digit 7/03/2022 (7 March 2022).

    See pic for an example of your script in action.
    Attached Images Attached Images

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

    Re: Transpose Varying Colums

    No, your output.

    23/02/2022 10:32 to 23/02/2022 10:32 in post #1
    7/03/2022 9:00 to 3/07/2022 9:00 in post #8

  12. #12
    Registered User
    Join Date
    02-22-2022
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    18

    Re: Transpose Varying Colums

    Apologies. I'm not explaining myself clear enough.

    I've attached a sample spreadsheet with the script, if you run it you can see it transposes 10/03 perfectly which is what I'm after. However it changes 9/03 to 3/09 which is not what I want.


    Thanks for bearing with me. Your help is so very appreciated.
    Attached Files Attached Files

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

    Re: Transpose Varying Colums

    You know the dates in Excel is terrible.

    Here A4 shows as 2022/3/10 14:34:00 both in cell and formula bar.
    That means it is genuine date and time.

    How is it showing there?

  14. #14
    Registered User
    Join Date
    02-22-2022
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    18

    Re: Transpose Varying Colums

    Oh. Our setting differences would make this more difficult. Here is my screenshot.
    Attached Images Attached Images

  15. #15
    Registered User
    Join Date
    02-22-2022
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    18

    Re: Transpose Varying Colums

    And formula bar appears as "10/03/2022 2:34:00 PM".

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

    Re: Transpose Varying Colums

    OK.

    Is the data imported from text file?
    If so, it is better/safer to read the data directly from text file.

  17. #17
    Registered User
    Join Date
    02-22-2022
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    18

    Re: Transpose Varying Colums

    It's copied from a webpage and I paste it into excel with "Match Destination Formatting".

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

    Re: Transpose Varying Colums

    Can you copy it to text editor like NotPad?

    Once you pasted to Excel, it automatically convert to appropriate data types, called auto casting, that I hate sometime...

  19. #19
    Registered User
    Join Date
    02-22-2022
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    18

    Re: Transpose Varying Colums

    Ok. So I did that and confirmed that all the cells in Column A are text. Still getting the same result unfortunately.
    Attached Images Attached Images

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

    Re: Transpose Varying Colums

    No,,,
    What I'm trying to say is that once you pasted the data in text editor, read the data directly from the text file and process before output to Excel by vba.
    So can you upload the text file here?

  21. #21
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,410

    Re: Transpose Varying Colums

    Here is another macro (Sheet1 assumed for data and output) that you might find interesting (no loops)...
    Please Login or Register  to view this content.
    NOTE: I cannot test the output for the dates here in my locale so you will have to tell me if they outputted correctly for your locale.
    Last edited by Rick Rothstein; 03-10-2022 at 11:49 PM.

  22. #22
    Registered User
    Join Date
    02-22-2022
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    18

    Re: Transpose Varying Colums

    Sorry, I'm unsure what you mean. I've just grabbed a section from the website and pasted it into notepad. Attached is the text file.
    Attached Files Attached Files

  23. #23
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,410

    Re: Transpose Varying Colums

    We posted at nearly the same time so you might have missed my posting. See Message #21 -- right before your last post.

  24. #24
    Registered User
    Join Date
    02-22-2022
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    18

    Re: Transpose Varying Colums

    You guys are amazing! How do you do this in so little code! This works, just a minor formatting issue as the date/time transposes as text.

    Still blown away at how skilled you guys are.

  25. #25
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,410

    Re: Transpose Varying Colums

    Quote Originally Posted by TravNoob View Post
    This works, just a minor formatting issue as the date/time transposes as text.
    Are you saying the date/time column is posting as text, not a real date/time? If so, is the day/month order correct? Let me know and I'll attempt to "fix" it (but first I need to know the actual problem).

  26. #26
    Registered User
    Join Date
    02-22-2022
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    18

    Re: Transpose Varying Colums

    The 'F' column is displayed as the 'raw' date/time "44630.61181".
    Also it would be great to have the output sorted by Column C (smallest number on top).

    The date/time is correct, just wrong format.

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

    Re: Transpose Varying Colums

    This will :

    Show converted joined data in Col.A and separate it from col.C.

    See if this works.
    Please Login or Register  to view this content.

  28. #28
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,410

    Re: Transpose Varying Colums

    I modified my original code a little as I realized I left some unqualified ranges. This code below fixes that, sorts your data as requested and attempts (because I cannot test your date ordering in my locale) to make the date/times real date/times instead of text... let me know if it worked or not.
    Please Login or Register  to view this content.

  29. #29
    Registered User
    Join Date
    02-22-2022
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    18

    Re: Transpose Varying Colums

    Quote Originally Posted by Rick Rothstein View Post
    I modified my original code a little as I realized I left some unqualified ranges. This code below fixes that, sorts your data as requested and attempts (because I cannot test your date ordering in my locale) to make the date/times real date/times instead of text... let me know if it worked or not.
    Please Login or Register  to view this content.

    Does the sort fine. Still doesn't format the date/time correctly. Data is correct, but format is not. Displays "44629.8458333333".
    Last edited by TravNoob; 03-11-2022 at 12:12 AM.

  30. #30
    Registered User
    Join Date
    02-22-2022
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    18

    Re: Transpose Varying Colums

    Quote Originally Posted by jindon View Post
    This will :

    Show converted joined data in Col.A and separate it from col.C.

    See if this works.
    Please Login or Register  to view this content.


    This incorrectly swaps the month and the date around for all entries, plus has the added step of opening the text file.
    Really interesting way of doing things, haven't seen this before.

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

    Re: Transpose Varying Colums

    Then try change
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.

  32. #32
    Registered User
    Join Date
    02-22-2022
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    18

    Re: Transpose Varying Colums

    Quote Originally Posted by jindon View Post
    Then try change
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.


    Swapped the "1" and the "0" and added the sort command from you previous script and it works great. Thanks so much for your effort. Still have that extra step of opening up the TXT file but it works. Thanks again!

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

    Re: Transpose Varying Colums

    OK, finally.
    As I said
    Is the data imported from text file?
    If so, it is better/safer to read the data directly from text file.

  34. #34
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,410

    Re: Transpose Varying Colums

    Okay, let me try one more time to get the date/time to display correctly (you still have to tell me if the day and month translate correctly though)...
    Please Login or Register  to view this content.

  35. #35
    Registered User
    Join Date
    02-22-2022
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    18

    Re: Transpose Varying Colums

    Quote Originally Posted by Rick Rothstein View Post
    Okay, let me try one more time to get the date/time to display correctly (you still have to tell me if the day and month translate correctly though)...
    Please Login or Register  to view this content.

    Works perfectly. Thank you!
    Very fast and clean.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Transpose Multiple (& Varying) Rows into Multiple (& Varying) Columns
    By Andrea9578 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-05-2017, 11:46 AM
  2. Transpose Multiple (& Varying) Rows into Multiple (& Varying) Columns
    By Andrea9578 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-05-2017, 02:05 AM
  3. Easy Way To Transpose 3 Colums of Data?
    By wings1080 in forum Excel General
    Replies: 17
    Last Post: 02-03-2015, 04:56 PM
  4. Code to transpose rows to colums
    By VBNewbie in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-23-2014, 09:41 AM
  5. Need to transpose one column into multiple with varying data
    By Topher77 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-21-2014, 06:06 PM
  6. being able to select a varying numbers of colums from a formula using a macro
    By belkin in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-25-2008, 08:53 PM
  7. Replies: 2
    Last Post: 02-19-2007, 04:53 PM

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