+ Reply to Thread
Results 1 to 18 of 18

Data Layout Conversion (Advanced Rows to Column ?)

  1. #1
    Registered User
    Join Date
    11-10-2010
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    13

    Question Data Layout Conversion (Advanced Rows to Column ?)

    Hi,

    I have a large CSV (comma delimited) which has data laid out in rows and each row contains about 10,000 separate inputs. This data is an output from a Simulink Simulation where variables have been saved on to the workspace saved as a .mat file then converted into csv (using a tool my colleague wrote). This tool was a modification from a script provided by mathworks therefore quite complex to modify to save the data in the format I need.

    Ive attached a spreadsheet with this post which contains the format the data currently is (input) and the format I need it to be in (output). As its an output from simulink some data are multidimensional arrays therefore not all the data can be converted straight from rows to columns. I have used the "Paste Special" and transposed the data for now, but I will need to do this repeatedly therefore looking for a better solution i.e. a vbscript that can do this for me.

    Any advice/solution would be appreciated.

    Thanks.

    Edit: Forgot to mention, the data might always not be in the same format. For e.g. sometimes the data might just be in the following format without any multidimensional arrays..
    Header 1
    1,2,3,4,5...
    Header 2
    3,4,5,6,7..
    Header 3.. and so on.
    Attached Files Attached Files
    Last edited by bibekpd; 10-10-2015 at 01:37 PM. Reason: Further Info.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,329

    Re: Data Layout Conversion (Advanced Rows to Column ?)

    Where you have Header 1, Header 2, etc., what do these headers really look like?
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    11-10-2010
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: Data Layout Conversion (Advanced Rows to Column ?)

    These header can be anything as they are whatever I set the Simulink workspace variables as.

    Currently they are I_ResolverValidity or I_<xx> for Inputs and O_MonitorFailed or O_<xx> for Outputs. If it helps they can be fully set as a string...

    I should have also mentioned the input are all integers. Boolean are represented as 1 & 0s.

    I was thinking of character comparison for each row and depending on the character type, decide which row to begin the column from ? That way I could decide if its a header (first row & x column) , array count [0] , [1] ... etc (second row & x column) and finally integer 1,-2,3.. etc to begin from third row and x column. Hope this makes sense.
    Last edited by bibekpd; 10-10-2015 at 02:01 PM. Reason: typo

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,329

    Re: Data Layout Conversion (Advanced Rows to Column ?)

    It makes sense, but I'd like to see some more realistic examples.

    I'd like to help you with this but, if I work with what you have provided (even with an explanation), and it doesn't work with your real life data, you're on your own.

    I don't want to go through the process twice.

    Regards, TMS

  5. #5
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Data Layout Conversion (Advanced Rows to Column ?)

    Maybe :

    Please Login or Register  to view this content.
    Last edited by karedog; 10-10-2015 at 02:58 PM. Reason: code correction

  6. #6
    Registered User
    Join Date
    11-10-2010
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    13

    Post Re: Data Layout Conversion (Advanced Rows to Column ?)

    Quote Originally Posted by TMS View Post
    It makes sense, but I'd like to see some more realistic examples.

    I'd like to help you with this but, if I work with what you have provided (even with an explanation), and it doesn't work with your real life data, you're on your own.

    I don't want to go through the process twice.

    Regards, TMS
    TMS, I completely understand your concern but unfortunately I cannot provide the exact data due to security restrictions at my work however I have created a sample csv with almost identical data but only for first 30 inputs.

    I hope I will be able to modify what you've started to suit my needs if it doesn't work with the real data on Monday.

    Please find attached.

    Thanks
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    11-10-2010
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: Data Layout Conversion (Advanced Rows to Column ?)

    Quote Originally Posted by karedog View Post
    Maybe :

    Please Login or Register  to view this content.
    karedog, thank you. it works with my first attachment but runtime error with the sample csv with 30 inputs which subsequently needs to be increased to 10000 for the actual set of data. This will also have 10+ headers and an "undefined" layout per se, in which the csv might contain multidimensional arrays or not and might not always be in the exact row every time.

  8. #8
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Data Layout Conversion (Advanced Rows to Column ?)

    How many rows do you have ? If it is exceeding 16384, then surely it will cause error, since the transposed data exceeded Excel's maximum columns (16384)

  9. #9
    Registered User
    Join Date
    11-10-2010
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: Data Layout Conversion (Advanced Rows to Column ?)

    No, rows will not exceed 100 even if i export all variables in the same file.

  10. #10
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Data Layout Conversion (Advanced Rows to Column ?)

    I have modified my code (correction to one line of code), please check it out. I have test with your sample files at post #1 and #6, and to me, it seem to work very well.

  11. #11
    Registered User
    Join Date
    11-10-2010
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: Data Layout Conversion (Advanced Rows to Column ?)

    Quote Originally Posted by karedog View Post
    I have modified my code (correction to one line of code), please check it out. I have test with your sample files at post #1 and #6, and to me, it seem to work very well.
    Works with my sample csv as well now. Will use it on the actual data and report back. Quite confident, it'll work.

    Cheeers!
    Last edited by bibekpd; 10-10-2015 at 03:24 PM. Reason: typo

  12. #12
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Data Layout Conversion (Advanced Rows to Column ?)

    I hope so, and thank you for the reputation points.


    Regards

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

    Re: Data Layout Conversion (Advanced Rows to Column ?)

    Alternative.

    This will read the data directly from cvs file.
    Please Login or Register  to view this content.
    Last edited by jindon; 10-10-2015 at 04:32 PM.

  14. #14
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,329

    Re: Data Layout Conversion (Advanced Rows to Column ?)

    I don't know ... you turn your back for 5 minutes

    Looks like you are in capable hands so I will bow out gracefully.


    Regards, TMS

  15. #15
    Registered User
    Join Date
    11-10-2010
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: Data Layout Conversion (Advanced Rows to Column ?)

    Quote Originally Posted by TMS View Post
    I don't know ... you turn your back for 5 minutes

    Looks like you are in capable hands so I will bow out gracefully.


    Regards, TMS
    You can help me understand karedog's solution or maybe point me in the right direction :P I wish to understand the macro before using it.. I only have a very vague idea of whats going on from "Columns("A:B").Insert xlShiftToRight" line :/

  16. #16
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,329

    Re: Data Layout Conversion (Advanced Rows to Column ?)

    Always run (new, untested) macros on a copy of your data, not the live file ... or make a backup copy of the live file first.

    Please Login or Register  to view this content.

    Regards, TMS

  17. #17
    Registered User
    Join Date
    11-10-2010
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: Data Layout Conversion (Advanced Rows to Column ?)

    Makes much more sense now. Thank you TMS.

  18. #18
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,329

    Re: Data Layout Conversion (Advanced Rows to Column ?)

    You're welcome. Thanks for the rep.

+ 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] Conversion of Set of Rows ro Column in new sheet.
    By apowale in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-10-2013, 07:40 AM
  2. Data layout between row and column
    By scottb in forum Excel General
    Replies: 3
    Last Post: 12-07-2010, 12:01 AM
  3. Convert data from column layout to row layout
    By maacmaac in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-28-2010, 03:28 PM
  4. layout the column from data
    By eb316 in forum Excel General
    Replies: 9
    Last Post: 09-17-2009, 03:03 PM
  5. Auto Layout Of Data In Column
    By ethanjames in forum Excel - New Users/Basics
    Replies: 4
    Last Post: 05-28-2009, 09:32 PM
  6. Advanced Filter to return Rows w/blank column
    By ChemistB in forum Excel General
    Replies: 3
    Last Post: 04-01-2009, 01:14 PM
  7. data conversion to rows
    By anandapani in forum Excel General
    Replies: 1
    Last Post: 12-15-2008, 04:47 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