Solved

Need to format CSV to inlude commas and single-quotes

Posted on 2010-08-30
6
576 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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

743 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

13 Experts available now in Live!

Get 1:1 Help Now