0

I'm trying to create a macro that will take a cell and split character strings separated by new lines into new rows. To demonstrate what I mean visually, if I have a cell that looks like this:

enter image description here

I want it to look like this after I run the macro: enter image description here

Right now I'm using the following code for my macro which clearly has something wrong with it:

Sub splitText()

Dim splitVals As Variant

Dim totalVals As Long

splitVals = Split(ActiveCell.Value, Chr(10))

totalVals = UBound(splitVals)

Range(Cells(ActiveCell.Row + 1, ActiveCell.Column), Cells(ActiveCell.Row + 1 + totalVals, ActiveCell.Column)).Value = splitVals

Selection.Delete Shift:=xlUp

End Sub

Instead of splitting it like I'd prefer it just copies the string before the first line break and copies that into the following cells

enter image description here

How can I change my code to work correctly?

cybernetic.nomad
  • 6,100
  • 3
  • 18
  • 31

0 Answers0