+ Reply to Thread
Results 1 to 5 of 5

Create CSV without extra Commas

  1. #1
    Registered User
    Join Date
    01-12-2010
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    25

    Create CSV without extra Commas

    Hi All,
    JBeaucaire helped me to create a macro that will create csv files for each worksheet of a workbook.The Macro works great.

    But i do have a requirement where i do not need extra commas (,) in the CSV. When the CSV are created for each worksheet, it adds additional commas in the end and my shell script throws it away becuase of the additional commas. Please help me modify the macro so that it does not add any commas for any cell which does not contain any value.

    I have attached 3 files -
    csvtest.xls - this has the macro which creates individual csv files for EACH worksheet in the workbook

    Sheet1.csv - This is the CSV file created fromt he Macro. If you look into it, it contains additional commas in the end of each line

    Sheet1_modified.csv - This is the output i expect from the Macro

    Link to the thread in which JBeaucaire helped me to create this macro -

    http://www.excelforum.com/excel-prog...v-files.html#2
    Attached Files Attached Files
    Last edited by naveenkharb; 02-02-2010 at 10:57 AM.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Create CSV without extra Commas

    Hello naveenkharb,

    Excel creates a CSV file based on the UsedRange. This range includes cells that have borders, even if they are empty. If you can, reduce your borders to only column "F". If that is not an option then you need a different macro.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Create CSV without extra Commas

    This may be a rough work-around, but I think you could open your csv in excel and save it as a csv of a different name. This would get rid of all commas after the last entry in the row with the most records. Would that solve your problem?
    Is your code running too slowly?
    Does your workbook or database have a bunch of duplicate pieces of data?
    Have a look at this article to learn the best ways to set up your projects.
    It will save both time and effort in the long run!


    Dave

  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: Create CSV without extra Commas

    You could solve this in the data by not having all those extra cells formatted with boxes. That's what's causing the extra cells to be included.

    Here's an amended version of the macro I wrote for you that should keep from having that problem.

    NOTE: Feel free to leave the comments at the top of the macro there....

    Please Login or Register  to view this content.
    _________________
    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!)

  5. #5
    Registered User
    Join Date
    01-12-2010
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    25

    Smile Re: Create CSV without extra Commas

    Hi JBeaucaire,
    Thanks again for helping me out. This modification does exactly what was needed. Thanks again. This Forum ROCKS !!!!!!!!

    And yes, i'll keep the comments as it is

    Thanks again for helping me out with this !!

+ 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