+ Reply to Thread
Results 1 to 9 of 9

Add double quotes to each field

  1. #1
    Registered User
    Join Date
    06-18-2004
    Posts
    29

    Add double quotes to each field

    HI all,

    Not sure if this is the correct forum for this question, feel free to move it if not.

    My issue is I have made an excel sheet that contains 500 rows and 19 columns.
    I need to export this as a CSV but when exproting, each field MUST be delimited by double quotes ex: "data"

    When taving either as a CSV or tab delimited text, it does not put the quotes in.
    How can I do this?

    The data must be formated as such:
    "product_sku2","product_s_desc","product_desc","TN_pic2.jpg","pic2.jpg","","","","","","","7","","N","","Product Name2","87.78","category/level1/level2|category2/level1/level2","1"

    Thank you in advance for any help provided.

  2. #2
    Registered User
    Join Date
    06-18-2004
    Posts
    29
    Anyone know how to do this?

  3. #3
    Forum Expert swatsp0p's Avatar
    Join Date
    10-07-2004
    Location
    Kentucky, USA
    MS-Off Ver
    Excel 2010
    Posts
    1,545
    One way: I assume your data is in A1:S500. In T1, enter this formula:

    =CONCATENATE("""",A1,"""") NOTE: that is 4 double quotes in succession, A1, then 4 more dble quotes.

    Copy this to the right 19 columns, then copy all 19 cells (T:AL) down the 500 rows.

    Now, all of your entries should be replicated, surrounded in double quotes. At this point you could delete columns A:S and then process your export.

    Does this work for you?
    Bruce
    The older I get, the better I used to be.
    USA

  4. #4
    Registered User
    Join Date
    06-18-2004
    Posts
    29
    does not seem to work correctly as after exporting to CSV, the CSV file shows this:

    """1805""","""plastex/mini-kit.jpg""","""Mini Master Kit""",""""""

    There are 3 Double quotes when there should only be 1

  5. #5
    Forum Expert swatsp0p's Avatar
    Join Date
    10-07-2004
    Location
    Kentucky, USA
    MS-Off Ver
    Excel 2010
    Posts
    1,545
    Odd, if there are only single quotes <before> you export, that you would end up with <triple> quotes after. Are you sure you need to add the quotes before the export?

    Maybe try this: Copy the range with the formulas, then Paste Special>Values to remove the formulas and end up with just the plain text entry e.g.: "data". Then export. Any change?

  6. #6
    Gary''s Student
    Guest

    Re: Add double quotes to each field

    If you feel comfortable with VBA, select the cells you want to process and run:

    Sub Macro1()
    Dim r As Range
    For Each r In Selection
    r.Value = Chr(34) & r.Value & Chr(34)
    Next
    End Sub
    --
    Gary's Student


    "swatsp0p" wrote:

    >
    > One way: I assume your data is in A1:S500. In T1, enter this formula:
    >
    > =CONCATENATE("""",A1,"""") NOTE: that is 4 double quotes in
    > succession, A1, then 4 more dble quotes.
    >
    > Copy this to the right 19 columns, then copy all 19 cells (T:AL) down
    > the 500 rows.
    >
    > Now, all of your entries should be replicated, surrounded in double
    > quotes. At this point you could delete columns A:S and then process
    > your export.
    >
    > Does this work for you?
    >
    >
    > --
    > swatsp0p
    >
    >
    > ------------------------------------------------------------------------
    > swatsp0p's Profile: http://www.excelforum.com/member.php...o&userid=15101
    > View this thread: http://www.excelforum.com/showthread...hreadid=475371
    >
    >


  7. #7
    K Dales
    Guest

    RE: Add double quotes to each field

    Don't know how to do this with a simple "Save As..." or anything, but you
    could build the output file yourself with code:

    Public Sub CSVOut(DataRange as Range)
    Dim RowCount as Integer, ThisRow as Integer
    Dim ColCount as Integer, ThisCol as Integer
    Dim CSVString as String
    ' Determine number of rows and columns
    RowCount = DataRange.Rows.Count
    ColCount = DataRange.Columns.Count
    ' Open file to write text output:
    Open "C:\CSVOutFile.csv" for Output as #1
    For ThisRow = 1 to RowCount ' Loop through rows
    CSVString = "" ' reset the output string
    For ThisCol = 1 To ColCount ' Loop through columns and build the string
    for a new line
    ' Get cell value and append it to the string with quotes ("):
    ' (Note: if this is the first column we do not need a comma,
    otherwise we do)
    If ThisCol <> 1 Then CSVString = CSVString & ","
    CSVString = CSVSTring & """ & DataRange.Cells(ThisRow,ThisCol).Text
    & """
    Next ThisCol ' end of column
    'Write the line of csv data to the text file:
    Print #1, CSVString
    Next ThisRow
    Close #1
    End Sub


    --
    - K Dales


    "npereira" wrote:

    >
    > HI all,
    >
    > Not sure if this is the correct forum for this question, feel free to
    > move it if not.
    >
    > My issue is I have made an excel sheet that contains 500 rows and 19
    > columns.
    > I need to export this as a CSV but when exproting, each field MUST be
    > delimited by double quotes ex: "data"
    >
    > When taving either as a CSV or tab delimited text, it does not put the
    > quotes in.
    > How can I do this?
    >
    > The data must be formated as such:
    > "product_sku2","product_s_desc","product_desc","TN_pic2.jpg","pic2.jpg","","","","","","","7","","N","","Product
    > Name2","87.78","category/level1/level2|category2/level1/level2","1"
    >
    > Thank you in advance for any help provided.
    >
    >
    > --
    > npereira
    > ------------------------------------------------------------------------
    > npereira's Profile: http://www.excelforum.com/member.php...o&userid=10799
    > View this thread: http://www.excelforum.com/showthread...hreadid=475371
    >
    >


  8. #8
    Tom Ogilvy
    Guest

    Re: Add double quotes to each field

    putting your data inside double quotes within the worksheet is a
    non-starter. When you export it, Excel will delimit the existing double
    quotes with double quotes and enclose the entry in double quotes. This is
    expected behavior - no mystery. This is what it has to do to reproduce what
    you have in the sheet, so the changes should not be made in the sheet.

    See K Dales' suggestion or look at this article:

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

    --
    Regards,
    Tom Ogilvy

    "swatsp0p" <[email protected]> wrote in
    message news:[email protected]...
    >
    > Odd, if there are only single quotes <before> you export, that you would
    > end up with <triple> quotes after. Are you sure you need to add the
    > quotes before the export?
    >
    > Maybe try this: Copy the range with the formulas, then Paste
    > Special>Values to remove the formulas and end up with just the plain
    > text entry e.g.: "data". Then export. Any change?
    >
    >
    > --
    > swatsp0p
    >
    >
    > ------------------------------------------------------------------------
    > swatsp0p's Profile:

    http://www.excelforum.com/member.php...o&userid=15101
    > View this thread: http://www.excelforum.com/showthread...hreadid=475371
    >




  9. #9
    Registered User
    Join Date
    06-18-2004
    Posts
    29
    Quote Originally Posted by Tom Ogilvy
    See K Dales' suggestion or look at this article:

    http://support.microsoft.com/default...b;en-us;291296
    Procedure to export a text file with both comma and quote delimiters in
    Excellent, this worked like a charm... Thanks

+ 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