Hello,
I want to remove the extra lines in cell contents.
Example:
Line 1
.
.
.
Line 2
.
.
.
Line 3
.
.
.
Line 4
I need output like below:
Line 1
Line 2
Line 3
Line 4
Only single blank line should remain between two lines.
Hello,
I want to remove the extra lines in cell contents.
Example:
Line 1
.
.
.
Line 2
.
.
.
Line 3
.
.
.
Line 4
I need output like below:
Line 1
Line 2
Line 3
Line 4
Only single blank line should remain between two lines.
Please try this code. Paste it to a standard code module of your workbook and remember to save it as macro enabled thereafter. The code will run on the ActiveSheet and delete extra rows where cells in column A are blank. It willl also insert rows where no blank is found.
Sub DoubleSpacing()
' 14 Sep 2017
Dim Blanks As Integer
Dim R As Long
Application.ScreenUpdating = False
With ActiveSheet
' look for values in column A
R = .Cells(.Rows.Count, "A").End(xlUp).Row
' loop from the end to row 2
For R = (R + 1) To 2 Step -1
If Len(.Cells(R, "A").Formula) Then
If Blanks Then
Blanks = 0
Else
.Rows(R + 1).EntireRow.Insert
End If
Else
If Blanks Then
.Rows(R).EntireRow.Delete
Else
Blanks = 1
End If
End If
Next R
End With
Application.ScreenUpdating = True
End Sub
Note that the code doesn't check if there might be cell content in columns other than column A. It wouldn't be very difficult to amend it to ensure that no non-blank rows are deleted but doing so would slow down the process quite a bit.
You could set up a Filter on the data. Then remove Blank lines from the Data Range. Not sure what version of office you're using. It's under Data Filter. No VBA required. Simple!
How do you save the module to a macro?