+ Reply to Thread
Results 1 to 4 of 4

Urgent help needed - exporting to csv file having format issues

  1. #1
    Registered User
    Join Date
    06-07-2017
    Location
    Nottingham, UK
    MS-Off Ver
    2013
    Posts
    15

    Urgent help needed - exporting to csv file having format issues

    I am new to vba and need some help as I can't work this out

    When trying to save some specific content from one of the worksheets in an excel workbook into a CSV file,I can't get the right output format. This is critical as some columns need text qualifiers and others do not and I have to get it right as the file will go into a enterprise solution.

    I have 5 columns A-E that holds data I need to export as a csv, columns A,C & E need text qualifiers, but B & D do not.

    The csv file has 2 header rows, which do not have any " qualifiers

    I am trying to get this to work but have 2 issues 1) Columns A,C & E need to be in quotes, with B & D not in quotes 2) The header in row 1 has extra ,,,, on the end which I want to remove

    The code I am using is below, and I've attached an image of a sample file to bring it to life.

    The file does the following 1) Selects a dynamic range of rows within columns A-E 2) Saves as a specific name with data & time included it it.

    Please Login or Register  to view this content.
    The output it gives me is:
    Export file name,,,, Need to... Get rid of ",,,." on end
    Column1,Column2,Column3,Column4,Column5 OK, as needed
    name 1,Group1,Description 1,1,0 Need " " around Name 1, Description 1 and 0
    Name 2,Group2,Description 2,1,0
    name 3,Group3,Description 3,1,0
    name 4,Group4,Description 4,1,0
    name 5,Group5,Description 5,1,0

    I need it to be:

    Export file name < No " or comma's at the end
    Column1,Column2,Column3,Column4,Column5 <- No "
    "name 1",Group1,"Description 1",1,"0" <- " only on columns 1,3 & 5
    "Name 2",Group2,"Description 2",1,"0"
    "name 3",Group3,"Description 3",1,"0"
    "name 4",Group4,"Description 4",1,"0"
    "name 5",Group5,"Description 5",1,"0"

    Original excel file looks like this: Forum_Sample.PNG

    I keep looping around different solutions, so need some expert guidance please.

    All suggestions welcome as getting desperate Thanks

    PS the above code could be completely wrong place to start so let me know.
    Attached Files Attached Files
    Last edited by enthusiastic amateur; 06-12-2017 at 04:22 PM.

  2. #2
    Forum Expert
    Join Date
    10-10-2016
    Location
    Sheffield
    MS-Off Ver
    365 and rarely 2016
    Posts
    3,210

    Re: Urgent help needed - exporting to csv file having format issues

    attaching the spreadsheet will elicit a quicker response. It can be done by go advanced, and scroll down to manage attachments, and attach a sample file. the macro enabled workbook

  3. #3
    Registered User
    Join Date
    06-07-2017
    Location
    Nottingham, UK
    MS-Off Ver
    2013
    Posts
    15

    Re: Urgent help needed - exporting to csv file having format issues

    Thanks for the hint... I've added.

  4. #4
    Registered User
    Join Date
    06-07-2017
    Location
    Nottingham, UK
    MS-Off Ver
    2013
    Posts
    15

    Re: Urgent help needed - exporting to csv file having format issues

    After a hard night, I've solved this will a little help out of the Forum.

    The trick was to not try to save the file at all, but to create a new file object and then add the data into it as I wanted it. This got around the funnies that Excel does.

    Thanks to all those who looked at this
    Thanks
    Graham

+ 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. Replies: 2
    Last Post: 01-15-2016, 09:20 AM
  2. [SOLVED] Error refreshing Powe Pivot Data file --Urgent help is needed
    By rv02 in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 04-20-2015, 11:23 AM
  3. [Urgent help needed]Need macros to copy from one file to another file
    By SantiSR7 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-05-2014, 02:33 PM
  4. [SOLVED] exporting text file issues with formatting
    By dalerdd in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 01-25-2013, 08:52 AM
  5. copy data from file a to file b urgent help needed
    By rjhe22 in forum Excel Programming / VBA / Macros
    Replies: 23
    Last Post: 01-10-2013, 10:22 AM
  6. recovered file but unreadable format!!urgent!!
    By jamesjaelisa in forum Word Formatting & General
    Replies: 2
    Last Post: 01-16-2012, 11:09 PM
  7. Date format problem when exporting to csv file
    By MikeWaring in forum Access Tables & Databases
    Replies: 3
    Last Post: 11-30-2010, 09:51 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