+ Reply to Thread
Results 1 to 13 of 13

Transpose vertical to horizontal data based on countif?

  1. #1
    Registered User
    Join Date
    07-04-2017
    Location
    Belgium
    MS-Off Ver
    365 ProPlus
    Posts
    81

    Transpose vertical to horizontal data based on countif?

    Hello all,

    I would like to transpose some vertical data (timestamps) in worksheet 3 horizontally to worksheet 2.

    Steps

    1. If you can't find the date from worksheet 2 column A in worksheet 3 column F, nothing should happen.
    2. If you can find the date, count the amount of times you find this date and copy the corresponding timestamps (to this date) to worksheet 2.
    E.g. 5/07/2017 has 2 timestamps in worksheet 3, thus worksheet 2 should only show a value in column Time1 and Time2.


    I don't really know how to loop through this or work with select case or so...

    Here below my flawed attempt, but the offset is a bit off and it doesn't copy the right amount of timestamps.

    Please Login or Register  to view this content.
    Expected result:

    Capture.JPG
    Attached Files Attached Files
    Last edited by dunnobe; 01-24-2018 at 01:55 PM.

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

    Re: Transpose vertical to horizontal data based on countif?

    See if this is how you wanted.
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    07-04-2017
    Location
    Belgium
    MS-Off Ver
    365 ProPlus
    Posts
    81

    Re: Transpose vertical to horizontal data based on countif?

    Very nice, but 100% Japanese to me!

    rep +1

    Is there any1 who knows another method so I can compare and learn?

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

    Re: Transpose vertical to horizontal data based on countif?

    I think I missed this part
    count the amount of times you find this date
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    07-04-2017
    Location
    Belgium
    MS-Off Ver
    365 ProPlus
    Posts
    81

    Re: Transpose vertical to horizontal data based on countif?

    Mmm, the result seems to be the same?

    (Which is good in this case)
    Last edited by dunnobe; 01-10-2018 at 10:46 AM.

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

    Re: Transpose vertical to horizontal data based on countif?

    Slower but easier to understnad?
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    07-04-2017
    Location
    Belgium
    MS-Off Ver
    365 ProPlus
    Posts
    81

    Re: Transpose vertical to horizontal data based on countif?

    Hey jindon,

    Thank you. I modified it a little bit to fit my needs.

    I do have a few general questions:

    1) It drops the 0 in front of a number (e.g. 97 rather than 097 in the columns Code1, Code2 etc.)
    How can I fix this?

    2) Do programmers turn data into a table before or after creating all of the data?

    3) Do programmers format the data during creation or after creating all of the data?
    E.g. I did ws2.Cells.Clear made me lose my formatting of ws2.

    Should I do ws2.Cells.ClearContents instead and preformat it myself? Should I insert formatting when creating the data?
    Should I just format everything after the data was created?


    Please Login or Register  to view this content.

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

    Re: Transpose vertical to horizontal data based on countif?

    Then why not reverse to copy...
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    07-04-2017
    Location
    Belgium
    MS-Off Ver
    365 ProPlus
    Posts
    81

    Re: Transpose vertical to horizontal data based on countif?

    Hey jindon,

    I'm very new to VBA. I'm just doing some learning by doing and studying other's work. I haven't really followed a course yet, might I might soon for work.
    This is only the 2nd attempt to make a tool so I was already happy to make some working loops. :p

    Copying seems to be slower, but I like the result better.
    Very nifty code and I made some additional changes to replace my code by this one.

    Please Login or Register  to view this content.
    2 questions:

    1) Does this server a purpose? I guess not as I don't need the value 0 in column 3 and 4?
    Please Login or Register  to view this content.
    2) The result in ws2.cells(2, 4) for the date 3/07/2017 is "ZE-Zending".
    When you look at ws1 you see that this date has 2 values "Var 7h36" and "ZE-Zending".
    "ZE-Zending" is the right, but why does it take this one and not the other one?
    Attached Files Attached Files
    Last edited by dunnobe; 01-11-2018 at 08:57 AM.

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

    Re: Transpose vertical to horizontal data based on countif?

    Please Login or Register  to view this content.
    could be
    Please Login or Register  to view this content.
    bit faster?

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

    Re: Transpose vertical to horizontal data based on countif?

    Because, it updates when next matched date is found.
    Please Login or Register  to view this content.
    Too slow anyway...

  12. #12
    Registered User
    Join Date
    07-04-2017
    Location
    Belgium
    MS-Off Ver
    365 ProPlus
    Posts
    81

    Re: Transpose vertical to horizontal data based on countif?

    Oh yes, I used a count time macro and that's definitely faster (about 4 secs).

    Thanks for showing different ways to achieve the same result!

  13. #13
    Registered User
    Join Date
    07-04-2017
    Location
    Belgium
    MS-Off Ver
    365 ProPlus
    Posts
    81

    Re: Transpose vertical to horizontal data based on countif?

    Hey jindon,

    I encountered a strange problem with Set c = rng2.Find(r.Value, , xlFormulas)
    If r.value = 15/01/2016, it sets c = 15/11/2016 and thus starts copying the values for both 15/01/2016 and 15/11/2016.

    E.g.

    15/01/2016: it shows the 2 timestamps of 15/01/2016 and the 4 timestamps of 15/11/2016!

    I highlighted some of these strange cases in red in wsSummary.

    Would you mind having another look?

    Please Login or Register  to view this content.
    SOLVED Set c = rng2.Find(r.Value, , xlFormulas, xlWhole)
    Attached Files Attached Files
    Last edited by dunnobe; 01-26-2018 at 08:27 AM.

+ 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 huge data from horizontal to vertical
    By AaruJaan in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-23-2017, 12:13 PM
  2. [SOLVED] Transpose data from horizontal to vertical in specific column
    By YasserKhalil in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-29-2016, 12:39 AM
  3. [SOLVED] Transpose vertical data into horizontal records vba
    By nolans18 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 05-27-2014, 08:50 PM
  4. [SOLVED] Data transpose (from vertical input to Horizontal output)
    By nur2544 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-22-2013, 11:12 AM
  5. Transpose Vertical Data to Horizontal
    By Randu555 in forum Excel General
    Replies: 5
    Last Post: 04-18-2013, 05:05 PM
  6. Replies: 1
    Last Post: 10-03-2012, 02:46 PM
  7. transpose data from horizontal to vertical in a specific column
    By elaine in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-08-2006, 12:10 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