Skip to content

Instantly share code, notes, and snippets.

@ndthanh
Created July 22, 2017 14:37
Show Gist options
  • Save ndthanh/39761488946fa08aba3c49ca3a7be672 to your computer and use it in GitHub Desktop.
Save ndthanh/39761488946fa08aba3c49ca3a7be672 to your computer and use it in GitHub Desktop.
Sub SplitCells()
'Update 20141024
Dim Rng As Range
Dim WorkRng As Range
On Error Resume Next
xTitleId = "Hoc Excel Online"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
For Each Rng In WorkRng
lLFs = VBA.Len(Rng) - VBA.Len(VBA.Replace(Rng, vbLf, ""))
If lLFs > 0 Then
Rng.Offset(1, 0).Resize(lLFs).Insert shift:=xlShiftDown
Rng.Resize(lLFs + 1).Value = Application.WorksheetFunction.Transpose(VBA.Split(Rng, vbLf))
End If
Next
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment