Solved

Need to format CSV to inlude commas and single-quotes

Posted on 2010-08-30
6
586 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
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
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.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…

920 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now