Thursday, February 19, 2015

Split String By Comma

The following routine splits the comma-separated contents of an active cell into strings and prints each result  below the active cell. It will overwrite the cells below the active cell.

Sub SplitByComma()

Dim arr As Variant
Dim row As Integer
Dim col As Integer

row = ActiveCell.row
col = ActiveCell.Column

arr = VBA.split(ActiveCell.Value, ",")
For i = 0 To UBound(arr)
    Cells(row + 1 + i, col).Value = Trim(arr(i))
Next i

End Sub

No comments:

Post a Comment