+ Reply to Thread
Results 1 to 15 of 15

Transpose many columns and rows to database structure

  1. #1
    Forum Contributor
    Join Date
    05-18-2004
    Location
    Portland, Oregon
    MS-Off Ver
    2016
    Posts
    182

    Transpose many columns and rows to database structure

    Hello All,

    I receive a simple CSV file with Ship-to, Supplier-Code, Part-Code all down rows (can be hundreds of rows)...then in the corresponding columns have the Demand, with the Calendar weeks (rolling 26 weeks) in row 1.

    I need the file to be transposed so it can be uploaded into a basic database, which has the columns: Ship-to, Supplier-Code, Part-Code, CW (calendar week), and QTY (demand).

    Lots of information out there on basic transposing, but this is a little harder and with my limited VBA this is beyond me.

    For simplicity, I think, I am trying to leave the Original data in sheet "Orig" and transpose it into "New". But I am open to any idea as long as it transposes correctly. I added for an example "Example of how it should look" sheet....this is a set of some of the data on how I would like it in the end so I can transfer the data into the database.

    Attached is my example file, which of course has been limited in size.

    Any ideas?

    Thanks in advance!

    Regards,
    Matt
    Attached Files Attached Files

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

    Re: Transpose many columns and rows to database structure

    This will read the data directly from CSV file, if the structure is always the same.
    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    05-18-2004
    Location
    Portland, Oregon
    MS-Off Ver
    2016
    Posts
    182

    Re: Transpose many columns and rows to database structure

    Hello Jindon, Cooool!

    So it works great on my test file (with actual data and with actual structure), then when I grab another file (with the same structure) I get this error:

    screenshot.142.jpg


    screenshot.143.jpg


    What am I doing wrong?

    The approach to just select the CSV is brilliant and the structure for all the files I have grabbed is the same.

    On further testing I found that when I open the CSV file and then save as "excel csv" it works...could the pure CSV format from the direct download be causing it issues?

    Many thanks!!

    Matt

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

    Re: Transpose many columns and rows to database structure

    Then I need to see the CVF file.

    Most probably you have blank row(s) before the heading...

  5. #5
    Forum Contributor
    Join Date
    05-18-2004
    Location
    Portland, Oregon
    MS-Off Ver
    2016
    Posts
    182

    Re: Transpose many columns and rows to database structure

    Hi Jindon,

    Hmmm, I am not sure how I can share without disclosing the confidential (however unimportant:-) information in the file. Looking at the file in NotePad I don't see a leading space or anything, just consecutive data separated by "," with no spaces.

    Is there a way for me to see and tell you?

    I can tell you that in the column header fields it has a "_" instead of a "-" which I have in my example. Does that make a difference?

    If there is no easy way to solve, I can live with opening and saving as an excel based CSV file...because your code works brilliantly when saved like that.

    Thanks,
    Matt

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

    Re: Transpose many columns and rows to database structure

    OK

    Can you just change
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    and see if it works.

  7. #7
    Forum Contributor
    Join Date
    05-18-2004
    Location
    Portland, Oregon
    MS-Off Ver
    2016
    Posts
    182

    Re: Transpose many columns and rows to database structure

    Unfortunately, exact same error.

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

    Re: Transpose many columns and rows to database structure

    Then I need you to do a step debug.

    While you are in VBE;
    1) go to [View] - [LocalWindow] then you will see the new pane below the code pane.
    2) click somewhere on the code and hit F8
    3) as you hit F8, it executes one line and you will see all the variables in the LocalWindow.
    4) Check "myTitle", if it loads heading. You can expand it if it has "+" sign.

  9. #9
    Forum Contributor
    Join Date
    05-18-2004
    Location
    Portland, Oregon
    MS-Off Ver
    2016
    Posts
    182

    Re: Transpose many columns and rows to database structure

    Hi Jindon,

    Like this:

    screenshot.144.jpg

    Thanks,
    Matt

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

    Re: Transpose many columns and rows to database structure

    I see it is not splitting, so it uses other character.

    This will read the data from "Orig" sheet and dump the result in "New" sheet.
    Please Login or Register  to view this content.

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

    Re: Transpose many columns and rows to database structure

    And just try change vbCrLF to vbCr or vbLf for the first code.

  12. #12
    Forum Contributor
    Join Date
    05-18-2004
    Location
    Portland, Oregon
    MS-Off Ver
    2016
    Posts
    182

    Re: Transpose many columns and rows to database structure

    Hi Jindon,

    the "orig" to "new" code works like a champ, thanks!

    So I tried the vbCrLF to vbCr same error.
    I then tried vbCrLF to vbLF and it made it through the code, imported the original CSV. But...it added an additional row after each loop with columns A:D data, 27 instead of 26...CW and QTY both were correct at 26 rows of data....does that make sense?

    Thanks!!
    Matt

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

    Re: Transpose many columns and rows to database structure

    That means the file might have more consecutive columns (comma) at the end in a row...
    Try this one then
    Please Login or Register  to view this content.

  14. #14
    Forum Contributor
    Join Date
    05-18-2004
    Location
    Portland, Oregon
    MS-Off Ver
    2016
    Posts
    182

    Re: Transpose many columns and rows to database structure

    Hi Jindon,

    That worked with the modification changing vbCrLf to vbLF!

    Please Login or Register  to view this content.
    Just brilliant!

    This is really great and I very much appreciate your fast and time saving approach. I just hope to one day understand how this code works, it looks a lot different than my attempt using the macro recorder.

    Well this is step 1 of the project, I am sure I will be back:-)

    Cheers,
    Matt
    Last edited by matt4003; 02-04-2017 at 01:37 AM. Reason: missed adding the second function

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

    Re: Transpose many columns and rows to database structure

    Yeah, you've just copied before I edited the post.

    Anyway thanks for the rep and marking "Solved".

+ 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. [SOLVED] Formula to transpose rows to new columns and columns to new rows in Excel
    By bjnockle in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 05-26-2014, 06:28 PM
  2. Replies: 1
    Last Post: 01-24-2014, 06:20 PM
  3. Replies: 14
    Last Post: 08-01-2013, 08:48 AM
  4. [SOLVED] Swapping rows for columns and columns for rows in a large database
    By Bloomingdales in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-19-2012, 06:06 PM
  5. [SOLVED] Transpose Columns to Rows (automatically inserts new rows)
    By kichkichkich in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 04-28-2012, 05:38 AM
  6. Replies: 2
    Last Post: 01-01-2012, 05:54 AM
  7. Replies: 4
    Last Post: 04-26-2007, 02:13 AM

Tags for this Thread

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