+ Reply to Thread
Results 1 to 7 of 7

VBA Code to Eliminate Trailing Commas in CSV File

  1. #1
    Forum Contributor
    Join Date
    12-09-2015
    Location
    Virginia, USA
    MS-Off Ver
    2007
    Posts
    121

    VBA Code to Eliminate Trailing Commas in CSV File

    I have a macro that will parse data and save it as a csv. Unfortunately, since I save it as a csv, it leaves a trail of commas in the file for any row that does not reach all of the headers so I have to manually open the file and backspace out all of the trailing commas.

    Is there a simple macro that could basically append the file that gets saved and eliminate commas that are located at the end of the line?

  2. #2
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,496

    Re: VBA Code to Eliminate Trailing Commas in CSV File

    Be nice to have an example (attachment) to work with.

  3. #3
    Forum Contributor
    Join Date
    12-09-2015
    Location
    Virginia, USA
    MS-Off Ver
    2007
    Posts
    121

    Re: VBA Code to Eliminate Trailing Commas in CSV File

    Here is how the file gets saved. The start and end in the header are variable. It could be one column long or it could be 100. When I save it as a csv, the body of the data always goes out to the very end, but I need the commas to stop at the end of line.
    Attached Files Attached Files

  4. #4
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    365 32bit Win
    Posts
    1,788

    Re: VBA Code to Eliminate Trailing Commas in CSV File

    Perhaps you could run something like this on the file after it's saved?

    Please Login or Register  to view this content.

  5. #5
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: VBA Code to Eliminate Trailing Commas in CSV File


    Or just obviously exporting the necessary only ! For that a workbook attachment and its explanation accordingly are requested …

  6. #6
    Forum Contributor
    Join Date
    12-09-2015
    Location
    Virginia, USA
    MS-Off Ver
    2007
    Posts
    121

    Re: VBA Code to Eliminate Trailing Commas in CSV File

    Here is what the data looks like right before I save as a csv.
    Attached Files Attached Files

  7. #7
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Question Re: VBA Code to Eliminate Trailing Commas in CSV File


    According to csv file format, as your data used 14 columns so each text line must have 13 commas as delimiters
    so your post #3 csv attachment is totally correct, nothin' to change !

    Question : why by hell do you need to create some csv file which does very not respect the csv file format ?!

+ 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] Remove trailing commas and spaces without changing text color format
    By Kinjal Doshi in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-24-2020, 08:19 AM
  2. Replies: 9
    Last Post: 11-23-2016, 12:22 PM
  3. Remove numerous trailing commas from text string that contains commas
    By JenSven1 in forum Outlook Programming / VBA / Macros
    Replies: 2
    Last Post: 05-23-2016, 10:19 PM
  4. Replies: 1
    Last Post: 05-23-2016, 11:05 AM
  5. Remove trailing commas
    By danallamas in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-23-2016, 11:04 AM
  6. Concatenate cell Title and remove trailing commas using Excel VB
    By missit in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-23-2013, 12:36 AM
  7. Extra trailing commas in exported CSV
    By lucidr in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-25-2006, 08:40 AM

Tags for this Thread

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