See this example below. I really just don't know how to programmatically enter the "alt+enter" for a cell string using the "cells()" function.
Before:
After:
Here's the requested attempt at the code:
Sub Button2_Click()
Dim lenrows
lenrows = Cells(Rows.Count, "A").End(xlUp).Row 'length of column 1 (from the start)
For i = 2 To lenrows
If Cells(i, 1) = "" Then ' for example the cell to the left of banana, cells(1,2) is techincally blank (not 100)
Cells(i - 1, 2) = Cells(i - 1, 2) & " " & Cells(i, 2) 'instead of " ", it would need to be something that enters "alt+enter"
Rows(i).EntireRow.Delete
If i = Cells(Rows.Count, "A").End(xlUp).Row Then 'next line "i = i - 1" would make it loop forever?
Exit Sub
End If
i = i - 1 'otherwise turtle, for example, wouldn't be added
End If
Next i
End Sub
When I run this, it actually runs indefinitely and crashes. Not sure what to enter to stop this. I think it has to do with the "i = i - 1", but if I don't add that line, it wouldn't add turtle with pear and potato
After incorporating comments, here's the final working code:
Sub Button4_Click()
Dim lenrows
lenrows = Cells(Rows.Count, "B").End(xlUp).Row 'length of column 1 (from the start)
For i = lenrows To 2 Step -1
If Cells(i, 1) = "" Then ' for example the cell to the left of banana, cells(1,2) is techincally blank (not 100)
Cells(i - 1, 2) = Cells(i - 1, 2) & Chr(10) & Cells(i, 2)
Rows(i).EntireRow.Delete
End If
Next i
End Sub