Solved

Need to format CSV to inlude commas and single-quotes

Posted on 2010-08-30
6
612 Views
Last Modified: 2012-05-10
I have an excel sheet with a single Column which is filled with email addresses.

I need to somehow format the list so that each email address is comma delimited, and has a single quote around it. So basically each cell needs to have a single quote around its content, and be comma delimited.

Here's how it looks now:
John@yahoo.com
Joe@gmail.com
Jane@msn.com

Here's my end goal:
'john@yahoo.com', 'joe@gmail.com', 'jane@msn.com'

Any ideas how to achieve this?
0
Comment
Question by:InfoTechEE
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 8

Expert Comment

by:sstone55423
ID: 33561382
You will need to write an Excel macro.  The export utility will not do that for you.
0
 

Author Comment

by:InfoTechEE
ID: 33561393
Is there a way to Import CSV files into MS SQL Server 2008...is there a wizard?

I'm sure it would have this ability.
0
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 33561635
InfoTechEE,In your example, are those three entries in a single cell, or is each entry in its own cell?
0
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
LVL 65

Expert Comment

by:rockiroads
ID: 33561712
maybe try a bulk insert http://sqlserver2000.databases.aspfaq.com/how-do-i-load-text-or-csv-file-data-into-sql-server.html or http://blog.sqlauthority.com/2008/02/06/sql-server-import-csv-file-into-sql-server-using-bulk-insert-load-comma-delimited-file-into-sql-server/


but do you want to runt his outside of sql server?

some excel vba code like this is a simple example
I specify the start row and col using irow and icol
I place results in row 1, col 5

Public Sub MergeColumns()

    Dim iRow As Integer
    Dim iCol As Integer
   
    'Specify start row/col
    iRow = 1
    iCol = 4
   
    While Worksheets("Sheet1").Cells(iRow, iCol) <> ""
        If Worksheets("Sheet1").Cells(1, 5) <> "" Then
            Worksheets("Sheet1").Cells(1, 5) = Worksheets("Sheet1").Cells(1, 5) & ","
        End If
        Worksheets("Sheet1").Cells(1, 5) = Worksheets("Sheet1").Cells(1, 5) & "'" & Worksheets("Sheet1").Cells(iRow, iCol) & "'"
        iRow = iRow + 1
    Wend
   
End Sub
0
 

Author Comment

by:InfoTechEE
ID: 33562681
matthewspatrick: Each entry is in its own cell. All the email addresses are in Column A, and each email address is on its own row, in its own cell.

rockiroads: To come to think about it, can't this be done with Cancatination formula?
0
 
LVL 65

Accepted Solution

by:
rockiroads earned 500 total points
ID: 33563873
concat will certainly put the values together but you still want the semicolon delimiter
you can iterate thru and create a formula but I can't see any other way

code posted earlier needs tidying up, should use a worksheet object as well as determing last row instead of checking each item

example of formula

    Dim iRow As Integer
    Dim iLastRow As Integer
    Dim iCol As Integer
    Dim ws As Worksheet
    Dim sFormula As String

   
    Set ws = Worksheets("Sheet1")
    iLastRow = ws.Range("A65536").End(xlUp).Row
   
    For iRow = 1 To iLastRow
        If iRow = 1 Then
            sFormula = "=CONCATENATE("
        Else
            sFormula = sFormula & "," & Chr$(34) & "," & Chr$(34) & ","
        End If
        sFormula = sFormula & "A" & iRow
    Next iRow
    Debug.Print sFormula
    sFormula = sFormula & ")"
    ws.Range("B2").Formula = sFormula


formula added to b2
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question