Results 1 to 8 of 8
  1. #1
    2 Star Lounger
    Join Date
    Mar 2004
    Posts
    129
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Appending to a CSV file (VBA/Excel/2003)

    I have a CSV file of data that I currently pull into Excel for data manipulation. If I add data to the file (after it has been pulled into an Excel spreadsheet), how can I use VBA to append the new data rows to the existing CSV file?

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Appending to a CSV file (VBA/Excel/2003)

    Isn't it easier just to overwrite the CSV file?

  3. #3
    2 Star Lounger
    Join Date
    Mar 2004
    Posts
    129
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Appending to a CSV file (VBA/Excel/2003)

    Actually yes, it would be and that is currently what I do. The data is date specific though. When I pull the data into Excel, I specify a certain date range since I don't need October's data in November's calculations for example. And when I save the file, it is in effect overwritten and I lose the non-November information. However, I want to be able to maintain a yearly data file from say January to December and simply append new data to the existing file. Any way I can do this?

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Appending to a CSV file (VBA/Excel/2003)

    If you only pull part of the data into Excel, how can you distinguish new data (in Excel) from the existing data (in the CSV file)? Please make your answer as specific as possible.

  5. #5
    2 Star Lounger
    Join Date
    Mar 2004
    Posts
    129
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Appending to a CSV file (VBA/Excel/2003)

    Let's say that I currently want to do calculations for October. I will pull what is essentially November's data file into Excel. If there are any data points that have dates that end before October begins, those data points (or rows) are deleted and October's Excel spreadsheet is in effect created. When I add data to October's spreadsheet, I export it as say October.csv currently, but it does not include any of the rows that were previously deleted. What I would like to do is have one data file that I can append and save new data to instead of twelve separate files. Any suggestions?

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Appending to a CSV file (VBA/Excel/2003)

    Should ALL rows from the October spreadsheet be appended to the original file, or only some?

  7. #7
    2 Star Lounger
    Join Date
    Mar 2004
    Posts
    129
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Appending to a CSV file (VBA/Excel/2003)

    No, the only rows that would need to be appended to the original file would be those that are added in October--therefore creating a cumulative file. This is the logic problem that I haven't been able to solve. For example, if I add five rows of data in October, how do I append only those five rows to the original file?

  8. #8
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Appending to a CSV file (VBA/Excel/2003)

    You can use ADO to read and write CSV-format data. You already had this thread and this thread on the reading part, so you just need to write the code to add records to that table. Right? Take a look at this thread for a link to a sample appllication that might help. And of course the Access forum has many gurus to help with SQL syntax, should it be needed.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •