March 21, 2012

Excel Macro to Split Cell Data with Delimiter and Copy in other Columns

Hi all,
Today I have written one more small macro in Excel to split the data with the delimiter and copy to the columns which are beside to the data.


Sub splitdata()

Dim data As String
Dim values As Variant
Dim i As Long

    Set DataRange = Range("A1").CurrentRegion
    Range("A1").Select
    For Each cell In Range("A1").CurrentRegion
       
        'Getting text from the cell
        data = cell.Text
       
        'MsgBox ("Data :" & data)
       
        'Gettings Values
        values = split(data, ",")
       
        For i = 0 To UBound(values)
            'MsgBox ("Value is: " & values(i))
            'Splitting to other columns
            cell.Offset(0, i + 1).Value = values(i)

        Next i

    Next cell  
 

'Autofit the content to the column
    Cells.EntireColumn.AutoFit
   
End Sub


Please send your feedback and comments to psrdotcom@gmail.com

No comments:

Featured Post

Java Introdcution

Please send your review and feedback to psrdotcom@gmail.com