Hello, all! First post for me. And I'm somewhat inexperienced on forums in general.
I had a similar issue to another post on this forum which is why I chose to sign up on OzGrid versus StackOverflow. However, I need some additional assist if possible.
Split Multi line Cell text Into Multiple Rows in range
What I need is for if there is only one line in the cell (ie there is no Chr(10)), for it to still show up in my recreated list.
Private Sub splitcells()
Application.ScreenUpdating = False
Dim LastRow As Long, x As Long, splitList As Variant, i As Long
LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
For x = LastRow To 2 Step -1
splitList = Split(Cells(x, 2), Chr(10))
If UBound(splitList) Then
For i = UBound(splitList) To 1 Step -1
Cells(x + 1, 3).Insert Shift:=xlDown
Cells(x + 1, 4).Insert Shift:=xlDown
Cells(x + 1, 3) = Cells(x, 1)
Cells(x + 1, 4) = splitList(i)
Cells(x, 3) = Cells(x, 1)
Cells(x, 4) = splitList(0)
Next i
End If
Next x
Application.ScreenUpdating = True
End Sub
Display More
Problem:
Also, just for a bonus, so more important to focus on the above, but I also have not used this particular method of moving on the next row before. If the data that needed to be split was in Column "C", how would I tell it to look there within the above script?
Below are some of the other "LastRow" variations I have tried in order to specify what column it looks in rather than just "A". I just wanted to demonstrate that I am attempting/experimenting/researching before just asking someone to solve my problems.
'Range("C1").Select
'LastRow = Cells.Find("*", After:=ActiveCell, SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
'Set LastRow01 = Cells.Find("*", After:=Sheet1.Cells(1, 3), SearchOrder:=xlByRows, SearchDirection:=xlPrevious) '.Row
'On Error GoTo 0
'If Not LastRow01 Is Nothing Then Application.Goto LastRow01, True
'Columns("C:D").Select
'LastRow = Selection.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
'Dim LastRow As Range
'LastRow = Range("C1:D50").Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
'LastRow = ActiveSheet.Columns("C:D").Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
Display More
Thank you, thank you, for any and all support.
-Mouse