+ Reply to Thread
Results 1 to 13 of 13

open csv files, do time stamp difference and paste result

  1. #1
    Registered User
    Join Date
    12-21-2011
    Location
    Chicago
    MS-Off Ver
    Excel 2007
    Posts
    30

    open csv files, do time stamp difference and paste result

    Hi guys, you all were such help last time I hope you can help now.

    What I am trying to do is the following:

    I have a folder with some .csv files, it can be 1 or 500 files, how many there are vary.

    I need to write a macro that will open each csv count the number of rows ( excluding the first row) and put the total in column G of my active sheet.

    The results need to be ordered by basically the file name, by that I mean, if I have 3 csv files named A, B, C, the results in column G should be in the same order from top to bottom.

    Thanks!
    Last edited by chi11; 01-04-2012 at 03:06 PM.

  2. #2
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: open csv files and count rows

    to get the number of 'rows' ( the first one ignored) in a csv file:

    Please Login or Register  to view this content.



  3. #3
    Registered User
    Join Date
    12-21-2011
    Location
    Chicago
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: open csv files and count rows

    Hi thanks for the response but I realized there is a problem with the data in the csv files.

    column A is the time stamp column but the problem is that it does not stay consistent, it changes. What I have found would be best would be to take the last cell in column A and minus it from cell A2 (A1 has wiring in it), this will give me the total time of the file. Then I want to put this in the active sheet, how would I go about doing this?

  4. #4
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: open csv files and count rows

    I have no idea what you are trying to accomplish.

  5. #5
    Registered User
    Join Date
    12-21-2011
    Location
    Chicago
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: open csv files and count rows

    ok let me try to explain again.

    1. I have a folder with .csv files. Those files have many columns in them but the first one A: is a time stamp.

    2.What I want to do is fine the total time each file has run.

    3.So If I open one file it has a time stamp starting in A2 as 20:29.3 (5/16/2011 5:20:29 am) and in the last cell of column A as 53:24.2 (5/16/2011 6:53:24 am).

    4.first I want to turn them into general numbers, so 20:29.3 turns into 40679.22256 and 53:24.2 turns into 40679.28709.

    5.Then take 40679.28709-40679.22256 and you have .06453 which means 32.55 seconds

    6.Then take that seconds and past it in the current active worksheet, then loop for all files in the active folder.

  6. #6
    Registered User
    Join Date
    12-21-2011
    Location
    Chicago
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: open csv files and count rows

    so this is what I came up with but it only works with one file at a time, I need this to loop though all of the files in the folder.

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    12-21-2011
    Location
    Chicago
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: open csv files and count rows

    so this is what I cam up with but it only works with one file at a time, I need this to loop though all of the files in the folder.

    Please Login or Register  to view this content.

  8. #8
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: open csv files and count rows

    So your thread title contradicts your purpose ...?
    to put the time difference into variable c01:

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    12-21-2011
    Location
    Chicago
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: open csv files and count rows

    thanks for the response, the thread title was originally what I wanted to do but I noticed after that it would not work right, that is why I want to use the time difference.

    can you please explain to me how I put the time difference in the variable, I don't know much about vba, but I am trying to learn. Thanks.

  10. #10
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: open csv files and count rows

    In my code it is in variable c01.

    Please post a sample csv file.

  11. #11
    Registered User
    Join Date
    12-21-2011
    Location
    Chicago
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: open csv files and count rows

    attached is an example of one the the csv files.
    Attached Files Attached Files

  12. #12
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: open csv files and count rows

    how do you know what the hour will be ?

    20:29.3 (5/16/2011 5:20:29 am)

  13. #13
    Registered User
    Join Date
    12-21-2011
    Location
    Chicago
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: open csv files and count rows

    I would just turn those into standard excel format, so 20.29.3 would turn into something like 40622.26423

+ 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