I am trying to remove only empty lines from cells in excel. Here is what I'm trying to accoplish:
+-----------------+ +---------------------+ +---------------------+
| EXAMPLE DATA | | EXPLANATION | | EXPECTED RESULT |
+-----------------+ +---------------------+ +---------------------+
| cell1_text1 | | cell1_text1 | | cell1_text1 |
| cell1_text2 | | cell1_text2 | | cell1_text2 |
+-----------------+ +---------------------+ +---------------------+
| | | cell2_empty_line | | cell2_text1 |
| cell2_text1 | | cell2_text1 | +---------------------+
+-----------------+ +---------------------+ | cell3_text1 |
| cell3_text1 | | cell3_text1 | | cell3_text2 |
| | | cell3_emptyline | +---------------------+
| cell3_text2 | | cell3_text2 | | cell4_text1 |
+-----------------+ +---------------------+ +---------------------+
| | | cell4_emptyline | | cell5_text1 |
| | | cell4_emptyline | +---------------------+
| cell4_text1 | | cell4_text1 | | cell6_text1 |
+-----------------+ +---------------------+ | cell6_text2 |
| cell5_text1 | | cell5_text1 | | cell6_text3 |
+-----------------+ +---------------------+ | cell6_text4 |
| cell6_text1 | | cell6_text1 | +---------------------+
| cell6_text2 | | cell6_text2 |
| cell6_text3 | | cell6_text3 |
| | | cell6_emptyline |
| cell6_text4 | | cell6_text4 |
+-----------------+ +---------------------+
I have found this script:
Sub RemoveCarriageReturns()
Dim MyRange As Range
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
For Each MyRange In ActiveSheet.UsedRange
If 0 < InStr(MyRange, Chr(10)) Then
MyRange = Replace(MyRange, Chr(10), "")
End If
Next
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub
but it doesn't give me desired result, it removes all breaklines in all cells.
+---------------------------------------------+
| CURRENT SCRIPT RESULT |
+---------------------------------------------+
| cell1_text1cell1_text2 |
+---------------------------------------------+
| cell2_text1 |
+---------------------------------------------+
| cell3_text1cell3_text2 |
+---------------------------------------------+
| cell4_text1 |
+---------------------------------------------+
| cell5_text1 |
+---------------------------------------------+
| cell6_text1cell6_text2cell6_text3cell6_text4|
+---------------------------------------------+
How can I test if row doesn't contain any other letter and delete only that row within cell? How can I apply that macro only to currenty selected cells?