Skip to content

Instantly share code, notes, and snippets.

@webtk
Last active January 10, 2018 07:05
Show Gist options
  • Save webtk/92030b4872fd0b480aa2fbeb4ba46a6f to your computer and use it in GitHub Desktop.
Save webtk/92030b4872fd0b480aa2fbeb4ba46a6f to your computer and use it in GitHub Desktop.
An excel macro for splitting cell has multiple newlines into multiple rows
Sub split_into_multi_rows()
'splits Text active cell
Dim splitVals As Variant
Dim totalVals As Long
splitVals = Split(ActiveCell.Value, Chr(10))
totalVals = UBound(splitVals)
'insert rows and delete active row
Dim counter
For counter = 0 To totalVals
Rows(ActiveCell.Row + 1).Insert
Rows(ActiveCell.Row + 1).Value = Rows(ActiveCell.Row).Value
Cells(ActiveCell.Row + 1, ActiveCell.Column).Value = splitVals(totalVals - counter)
Next
Rows(ActiveCell.Row).Delete
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment