+ Reply to Thread
Results 1 to 29 of 29

Append multiple csv files into master file?

  1. #1
    Registered User
    Join Date
    08-19-2009
    Location
    Long Beach
    MS-Off Ver
    CA
    Posts
    43

    Append multiple csv files into master file?

    Hi,

    I have about 100 csv files of the same format that I would like to append into a single master file. Order is not important for appending (I can do a column sort later) I can do copying and pasting, but this will take a long time especially because I will creating more master files from completely different CSVs in the future. Is there a faster way to append CSV files?

    Thanks
    Last edited by Delta223; 01-23-2010 at 04:25 PM.

  2. #2
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: Append multiple csv files into master file?

    An old keeper for the Andy pope folder


    AutoLinked keywords will cause extra spaces before keywords. Extra spacing is NOT transferred when copy/pasting, but IS if the keyword uses "quotes".
    Please Login or Register  to view this content.
    If the solution helped please donate to RSPCA

    Site worth visiting: Rabbitohs

  3. #3
    Registered User
    Join Date
    08-19-2009
    Location
    Long Beach
    MS-Off Ver
    CA
    Posts
    43

    Re: Append multiple csv files into master file?

    Thanks, so if I'm reading this right, all files in the "C:\temp\" folder with be automatically appended when running this macro, correcT?

    If so I iwll need to change the folder because there is already a "temp" folder on my hard drive. I don't really work with macros and hope this won't cause a problem elsewhere in the script.

  4. #4
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: Append multiple csv files into master file?

    Hi Delta223
    yes thats right - it will only look for csv file in the temp folder. and you can change the path to the new folder.
    Last edited by teylyn; 02-04-2010 at 02:46 AM.

  5. #5
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: Append multiple csv files into master file?

    looking closer at Andy's code it wont do what you require
    you'll need some thing like
    Please Login or Register  to view this content.
    its untested

  6. #6
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: Append multiple csv files into master file?

    Ok I've tested this

    Please Login or Register  to view this content.

  7. #7
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: Append multiple csv files into master file?

    Forgot about
    Please Login or Register  to view this content.
    change it to
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    08-19-2009
    Location
    Long Beach
    MS-Off Ver
    CA
    Posts
    43

    Re: Append multiple csv files into master file?

    haha thanks for the revision

  9. #9
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: Append multiple csv files into master file?

    Dont forget

    To mark your thread solved do the following:
    - Go to the first post
    - Click edit
    - Click Advance
    - Just below the word "Title:" you will see a dropdown with the word No prefix.
    - Change to Solve
    - Click Save

  10. #10
    Registered User
    Join Date
    08-19-2009
    Location
    Long Beach
    MS-Off Ver
    CA
    Posts
    43

    Re: Append multiple csv files into master file?

    Hi,

    I tried it today and immediately when changing the "Input" line to "Line Input" it gave an error prompt and changed to a red warning color. See attached picture. Any idea what's causing this error?
    Attached Images Attached Images

  11. #11
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: Append multiple csv files into master file?

    HiDelta223
    change
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    which is short hand for
    Please Login or Register  to view this content.
    this one was a typo
    Please Login or Register  to view this content.
    Last edited by pike; 01-23-2010 at 06:34 PM.

  12. #12
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: Append multiple csv files into master file?

    I didnt test it as well as i though
    use
    Please Login or Register  to view this content.

  13. #13
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: Append multiple csv files into master file?

    Hi Delta223
    You spend a lot of time looking at this thread everything OK?

  14. #14
    Registered User
    Join Date
    08-19-2009
    Location
    Long Beach
    MS-Off Ver
    CA
    Posts
    43

    Re: Append multiple csv files into master file?

    Hi,

    I was having major issues with excel trimming the leading 0s on my CSV files as soon as it loaded the file. i found a workaround by saving the output file as a tab delimited .txt file (my csv importer apparently accepts this)

    how can I get your macro to work with tab delimited .txt files?
    Last edited by Delta223; 01-27-2010 at 05:07 PM.

  15. #15
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: Append multiple csv files into master file?

    good stuff!

  16. #16
    Registered User
    Join Date
    08-19-2009
    Location
    Long Beach
    MS-Off Ver
    CA
    Posts
    43

    Re: Append multiple csv files into master file?

    thanks pike, my final question is how can I get your macro to work with tab delimited .txt files?

  17. #17
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: Append multiple csv files into master file?

    Hey Delta223

    Just change csv to txt should do the trick

  18. #18
    Registered User
    Join Date
    08-19-2009
    Location
    Long Beach
    MS-Off Ver
    CA
    Posts
    43

    Re: Append multiple csv files into master file?

    Hi,

    It did not work. I was prompted with "runtime error 70: permission denied" clicking on debug mode showed the window in the attached image.

    Any idea what the issue is?
    Attached Images Attached Images
    Last edited by Delta223; 01-29-2010 at 12:25 AM.

  19. #19
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: Append multiple csv files into master file?

    Hi Delta223
    I've test this with the C:\Temp\Temp\MasterCopy.txt and the files .txt to add to it from
    C:\Temp\
    Please Login or Register  to view this content.

  20. #20
    Registered User
    Join Date
    08-19-2009
    Location
    Long Beach
    MS-Off Ver
    CA
    Posts
    43

    Re: Append multiple csv files into master file?

    Hi,

    I tried it again with your new code for ptesttxt

    I changed the root "temp" folder to /testdir/ (if i understand coorectly this is where the files to be appended go)

    I changed the 2nd "temp" folder where the master list is saved to /mtr/

    I changed MasterCopy.txt to masterlist.txt

    All of these of couse match the folder layout i have arranged.

    It did not work and gave the exact error as last time.

    here is the code I used:

    Sub ptesttxt()
    Dim strPathMaster$, strFile$, strPath$, tmpLine$
    strPath = "C:\testdir\"
    strPathMaster = "C:\testdir\mtr\masterlist.txt"
    ChDir strPath
    strFile = Dir("*.txt")
    Do While Len(strFile) > 0
    Open strPathMaster For Append As #2
    Open strFile For Input As #1
    Do Until EOF(1)
    Line Input #1, tmpLine
    Print #2, tmpLine
    Loop
    Close #2
    Close #1
    strFile = Dir
    Loop
    End Sub

  21. #21
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: Append multiple csv files into master file?

    Hello Delta223

    Please Login or Register  to view this content.
    Check if this is the exact path and file name
    also how did you create the txt file?
    You will need to saveas txt not just change the name??
    Last edited by pike; 01-29-2010 at 02:59 AM.

  22. #22
    Registered User
    Join Date
    08-19-2009
    Location
    Long Beach
    MS-Off Ver
    CA
    Posts
    43

    Re: Append multiple csv files into master file?

    hi, it is the exact path and i created the file through word

  23. #23
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243

    Re: Append multiple csv files into master file?

    hi all,

    Sorry for cutting in on this one Pike ;-)

    Quote Originally Posted by Delta223 View Post
    Hi,
    It did not work. I was prompted with "runtime error 70: permission denied" clicking on debug mode showed the window in the attached image.
    Any idea what the issue is?
    This may occur if you already/still have the file open in Word from when you created it. If you have closed the file & it still happens, (in case you have other word files open) try closing Word down completely before running the macro.

    You can use the below function to test for the file being locked...
    Please Login or Register  to view this content.
    hth
    Rob
    Rob Brockett
    Kiwi in the UK
    Always learning & the best way to learn is to experience...

  24. #24
    Registered User
    Join Date
    08-19-2009
    Location
    Long Beach
    MS-Off Ver
    CA
    Posts
    43

    Re: Append multiple csv files into master file?

    Hi, I ran the above recording for checking if the file was locked. It didn't seem to do anything.

  25. #25
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: Append multiple csv files into master file?

    Hi Delta 223 you will have you create new txt files from the csv files?

  26. #26
    Registered User
    Join Date
    08-19-2009
    Location
    Long Beach
    MS-Off Ver
    CA
    Posts
    43

    Re: Append multiple csv files into master file?

    which csv files are you referring to: masterlist.csv, or the .csv files that are to be appended?

  27. #27
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: Append multiple csv files into master file?

    Delta223
    SaveAs all csv to txt
    other wise start for scratch and with "note pad" create new txt files

  28. #28
    Registered User
    Join Date
    08-19-2009
    Location
    Long Beach
    MS-Off Ver
    CA
    Posts
    43

    Re: Append multiple csv files into master file?

    this will take quite some time.

    I will use your original script to append the csv files without leading zero problems on the zip codes and see if at east they work

  29. #29
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: Append multiple csv files into master file?

    Delta223

    Hard to say where did the csv come from ? if they from an xls why not save the xls to txt to keep the zeros

    something it better to start from the begining instead of fixing fixups

+ 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