Good Afternoon,
The code below was working fine, but for some reason I am getting the below error now and are not sure what the deal is.
Run-Time Error '1004':
Cannot use that command for overlapping selections.
Goal: I am trying to search through Columns A,B,C,D and delete rows that contain the following items. Below is the code I have been using.
#N/A
#VALUE!
Blank Values
Rows that contain a cell with a single space
Rows that contain a Cell that contain the value 0 (0 by itself)
Rows that contain a Cell that contain $0.00
Sub DeleteInvalidData()
Dim rngFound As Range, rngToDelete As Range
Dim strFirstAddress As String
Dim varList As Variant
Dim lngCounter As Long
varList = VBA.Array("#N/A", "#VALUE!", " ", "", "0", "$0.00")
For lngCounter = LBound(varList) To UBound(varList)
With Sheets("ChargeMaster_Template").Range("A:C")
Set rngFound = .Find( _
What:=varList(lngCounter), _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=True _
)
If Not rngFound Is Nothing Then
If rngToDelete Is Nothing Then
Set rngToDelete = rngFound
Else
Set rngToDelete = Application.Union(rngToDelete, rngFound)
End If
strFirstAddress = rngFound.Address
Set rngFound = .FindNext(after:=rngFound)
Do Until rngFound.Address = strFirstAddress
Set rngToDelete = Application.Union(rngToDelete, rngFound)
Set rngFound = .FindNext(after:=rngFound)
Loop
End If
End With
Next lngCounter
If Not rngToDelete Is Nothing Then rngToDelete.EntireRow.Delete
End Sub
As always, any help is greatly appreciated.
Bookmarks