Your error is because your selection (the one you made manually before running the sub) includes the same cell twice, at least once. Edit: this could be due to multiple cells on the same row being empty, then you're selecting the entire row of each of those cells! See code edit below for a fix.
You should try to avoid using Select
, despite the Macro Recorder using it a lot. See here: How to avoid using Select in Excel VBA macros
So a better format for your sub would be this:
Sub Cleanse()
' Cleanse Macro for deleting rows where cells in a range are blank
'
Dim myRange as Range
' Set the selection range to the first column in the used range.
' You can use this line to select any range you like.
' For instance if set on manual selection, you could use
' Set myRange = Selection. But this won't solve your actual problem.
Set myRange = ActiveSheet.UsedRange.Columns(1)
' Delete all rows where a cell in myRange was blank
myRange.SpecialCells(xlCellTypeBlanks).EntireRow.Delete
End Sub
Edit: Can cycle over all columns like below, avoids overlapping ranges from EntireRow
.
Sub Cleanse()
' Cleanse Macro for deleting rows where cells in a range are blank
'
Dim myRange as Range
Dim colNum as Long
' Cycle over all used columns
With ActiveSheet
For colNum = 1 To .UsedRange.Columns.Count + .UsedRange.Columns(1).Column
' Set the selection range to the column in used range.
Set myRange = .UsedRange.Columns(colNum)
' Delete all rows where a cell in myRange was blank
myRange.SpecialCells(xlCellTypeBlanks).EntireRow.Delete
Next colNum
End With
End Sub