Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Need to format CSV to inlude commas and single-quotes

Posted on 2010-08-30
6
Medium Priority
?
623 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 93

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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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 2000 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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

886 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