Solved

Need to format CSV to inlude commas and single-quotes

Posted on 2010-08-30
6
594 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

786 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