Try this
Private Sub btnDelete_Click()
Dim LastRow As Long, LastCol As Long
Dim RowNo As Long, ColNo As Long
LastRow = Range("A" & Rows.Count).End(xlUp).Row
LastCol = Cells(1, Columns.Count).End(xlToLeft).Column
For RowNo = LastRow To 2 Step -1
If WorksheetFunction.CountA(Rows(RowNo)) = 0 Then
Rows(RowNo).EntireRow.Delete
End If
Next
For ColNo = LastCol To 1 Step -1
If WorksheetFunction.CountA(Columns(ColNo)) = 0 Then
Columns(ColNo).EntireColumn.Delete
End If
Next
End Sub
You might need to change this line
LastRow = Range("A" & Rows.Count).End(xlUp).Row
to this
LastRow = ActiveSheet.UsedRange.Rows.Count
in case column A is not the longest column of data.
N.B. this also removes blank columns.
Hope this helps
Bookmarks