PDA

View Full Version : delete blank rows in excel using VBA



Alqahtanir
11-29-2023, 01:31 PM
How to delete blank rows in excel using VBA?

Aussiebear
11-29-2023, 01:45 PM
Welcome to VBAX Alqahtanir. You could try the following code


Public Sub DeleteBlankRows()
Dim SourceRange As Range
Dim EntireRow As Range
Set SourceRange = Application.Selection
If Not (SourceRange Is Nothing) Then
Application.ScreenUpdating = False
For I = SourceRange.Rows.Count To 1 Step -1
Set EntireRow = SourceRange.Cells(I, 1).EntireRow
If Application.WorksheetFunction.CountA(EntireRow) = 0 Then
EntireRow.Delete
End If
Next
Application.ScreenUpdating = True
End If
End Sub