Thread: Excel format
View Single Post
 
Old 05-12-2017, 08:33 AM
NoSparks NoSparks is offline Windows 7 64bit Office 2010 64bit
Excel Hobbyist
 
Join Date: Nov 2013
Location: British Columbia, Canada
Posts: 842
NoSparks is a glorious beacon of lightNoSparks is a glorious beacon of lightNoSparks is a glorious beacon of lightNoSparks is a glorious beacon of lightNoSparks is a glorious beacon of light
Default

Don't know what you're actually working with or its layout so have assumed IP addresses are in column A of Sheet1 starting in A1 and write the result to C1.
Setup a sample test sheet for experimentation.
I suspect the C1 cell will contain more characters than Excel can display but you should be able to copy and paste the entire cell value provided it doesn't exceed 32,767 characters.
Code:
Sub reFormat()
    Dim lr As Long, i As Integer, str As String
    Dim arr As Variant

    lr = Cells(Rows.Count, "A").End(xlUp).Row
    arr = Sheets("Sheet1").Range(Cells(1, 1), Cells(lr, 1)).Value
    str = Chr(39)
    For i = LBound(arr) To UBound(arr)
        str = str & arr(i, 1) & Chr(39) & Chr(44) & Chr(39)
    Next i
    str = Left(str, Len(str) - 2)
    Range("C1").Value = str
End Sub
Reply With Quote