Last active
January 10, 2018 07:05
-
-
Save webtk/92030b4872fd0b480aa2fbeb4ba46a6f to your computer and use it in GitHub Desktop.
An excel macro for splitting cell has multiple newlines into multiple rows
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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