+ Reply to Thread
Results 1 to 3 of 3

Slight problem - routine to add quotes to a column

  1. #1

    Slight problem - routine to add quotes to a column

    Hi,

    I'm using the following code to enclose all values in a specific column
    (Excel column 'CC') in a CSV file (obviously when opened in Excel).

    Sub Test()
    Dim RangeFirstColumn As Range
    Dim i As Range
    Set RangeFirstColumn = Range("CC2", Range("CC" &
    Rows.Count).End(xlUp).Address)
    For Each i In RangeFirstColumn
    If Len(i.Value) > 0 Then i = Chr(34) & i.Value & Chr(34)
    Next i
    End Sub

    The problem is, when I open up the resulting .csv in Notepad, the field
    in question in each row is now enclosed in three quotation marks
    instead of the expected one (e.g. """010""" rather than "010"). Could
    anyone advise me of what changes I need to make to my code? Many thanks.


  2. #2
    Tom Ogilvy
    Guest

    Re: Slight problem - routine to add quotes to a column

    Since you place quotes in the text in the cell, excel puts in more quotes so
    your quotes are retained.

    http://support.microsoft.com/default...b;en-us;291296
    Procedure to export a text file with both comma and quote delimiters in
    Excel

    --
    Regards,
    Tom Ogilvy


    <[email protected]> wrote in message
    news:[email protected]...
    > Hi,
    >
    > I'm using the following code to enclose all values in a specific column
    > (Excel column 'CC') in a CSV file (obviously when opened in Excel).
    >
    > Sub Test()
    > Dim RangeFirstColumn As Range
    > Dim i As Range
    > Set RangeFirstColumn = Range("CC2", Range("CC" &
    > Rows.Count).End(xlUp).Address)
    > For Each i In RangeFirstColumn
    > If Len(i.Value) > 0 Then i = Chr(34) & i.Value & Chr(34)
    > Next i
    > End Sub
    >
    > The problem is, when I open up the resulting .csv in Notepad, the field
    > in question in each row is now enclosed in three quotation marks
    > instead of the expected one (e.g. """010""" rather than "010"). Could
    > anyone advise me of what changes I need to make to my code? Many thanks.
    >




  3. #3

    Re: Slight problem - routine to add quotes to a column

    Thanks Tom


+ 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