+ Reply to Thread
Results 1 to 6 of 6

Renaming .dat to .csv, run through macros and save in correct folder

  1. #1
    Registered User
    Join Date
    12-17-2010
    Location
    Sacramento, CA
    MS-Off Ver
    Excel 2003
    Posts
    3

    Smile Renaming .dat to .csv, run through macros and save in correct folder

    Someone help! I have a massive project that I need to complete by using macros and I do not know how to complete it. I have a few of the codes needed completed. Here is what I need help with:

    I have four folders
    New Raw Data DC (T:\Program Circuit Board\P4911 Board Data\ NEW RAW DATA\DC)
    New Raw Data Current (T:\Program Circuit Board\P4911 Board Data\ NEW RAW DATA\I)
    Processed Raw Data (T:\Program Circuit Board\P4911 Board Data\ PROCESSED RAW DATA)
    Complete (T:\Program Circuit Board\P4911 Board Data\ COMPLETE)

    I have five.dat files that will be in the New Raw Data DC folder (all ending with A's) and five.dat files that will be in the New Raw Data Current folder (all ending with B's) The ten .dat files will be named xxxxx-A.dat, xxxxx-B.dat, yyyyy-A.dat and yyyyy-B.dat, etc. They correspond with one another. The file numbers will always be different. I need my macro to rename all .dat files as .csv files, open them as .csv files and delete the .dat files out of the New Raw Data folders, having them empty and ready to have new data received and saving the .csv files in the Processed Raw Data folder.

    With my ten .csv files open, I need them to run through a template already created. This is the tricky part in my opinion. I need only two files (xxxxx-A and xxxxx-B) to go into the template at a time. After ran through template, I need the template to save in the Complete folder as the tag number (xxxxx).xls. This needs to happen five times, each one being saved as a .xls in the Complete folder. Each .xls file can be saved and close but the .csv still need to stay open.

    I will then use my second macro to compile all .csv files open through a master summary template (one that which will keep growing and growing – no overwriting please). I need the .csvs to do this and somehow add to not overwrite (new .csvs to be added to next available column)

    After the master summary page runs with the ten .csv, all the .csvs can close (being saved in processed raw data) and the master page can close (being saved in completed).

    I know its a lot but I need help!!!! JJ thank youu!!!!

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Renaming .dat to .csv, run through macros and save in correct folder

    So Holly, what is your question? What have you done so far? We can help you along with snippets and all, but you want to build this yourself, right, so you fully understand it and can maintain/adjust it as needed, yes?

    So, something simple to get you started. To rename xxxxx-A.dat file as xxxxx-A.csv moving it to another folder in the process is pretty easy:

    Please Login or Register  to view this content.


    Now, along with moving the file you could also open it, process it with your templates in whatever manner you have in mind, all before you set the next fName to start the loop again.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    12-17-2010
    Location
    Sacramento, CA
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: Renaming .dat to .csv, run through macros and save in correct folder

    Thanks so much! This is exactly what I needed to begin.

    What I am basically trying to do is have corresponding A and B files (two .csv) being copied into a template (with macro, already created) to process data individually and then again with allllll of the A and B files together to process data in a master analysis (with macro, already created). I am just having trouble moving and naming things to get this all to flow.....

    From your code, I have all 10 (5 A files and 5 B files) in a folder together. How would I have a macro call out to open only two at a time, two that match with corresponding file numbers? For example, I have 1A.csv, 1B.csv, 2A, 2B, 3A, 3B, 4A, 4B, 5A and 5B all in one data folder now. What kind of callout would I have to do to only have corresponding 1A and 1B open together? Mind you these numbers will be changing....

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Renaming .dat to .csv, run through macros and save in correct folder

    I think the "A" and "B" thing will still be the trick for you in a secondary loop. This macro would go in the workbook with your "template".

    Open the template workbook
    Open the VBeditor
    Insert an empty module (insert > module)
    Paste in this code:
    Please Login or Register  to view this content.
    Edit the sheet names in the code (underlined) for accuracy
    Edit the copy values code in each With wbA and the With wbB sections...
    Give it a try...

  5. #5
    Registered User
    Join Date
    12-17-2010
    Location
    Sacramento, CA
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: Renaming .dat to .csv, run through macros and save in correct folder

    It isn't doing anything. Maybe I needed to be a bit more clear...

    Once opened, I would like 1-A.csv data range A1 through F685 copy and pasted into Cell A1 Sheet "Voltage" of Template and 1-B.csv data range A1 through F685 copy and pasted into Cell A1 Sheet "Current" of Template.....they are being put into two different places...

  6. #6
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Renaming .dat to .csv, run through macros and save in correct folder

    Don't put this macro in the Template workbook, put it in another workbook and run it from there.

    Be sure to edit the macro paths if they are not correct.

    Try running the macro using F8 in the VBeditor so that you can check each line of code actually does what you expect, that it doesn't skip the main DO/LOOP altogether.
    Please Login or Register  to view this content.

+ 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