M
ms
I have a procedure called that looks for a negative sign (*-*) in the D column
for all records. If it exists, the entire row is deleted. The procedure below
works well for this situation, BUT when there are no records with the negative
sign in the D column it deletes the first record in row 1. The Range somehow is
set for the value in the D column for row 1.
I have been unable to stop this so far.
Does anyone have a way to not delete row one if the filter is not met?
Here is the procedure:
Sub CleanCancelledChks()
Dim r As Range
With ActiveSheet
ActiveSheet.Columns("A:A").Select
Set r = .Range(.Range("D2"), .Range("D" & _
Rows.Count).End(xlUp))
.Columns("D").AutoFilter Field:=1, Criteria1:="=*-*"
Set r = r.SpecialCells(xlCellTypeVisible)
.AutoFilterMode = False
r.EntireRow.Delete
End With
End Sub
Here is 2 records as an example. The first one in the list will be deleted by
this procedure though the D column does not have a negative sign on the right
side of the value as shown in the next example below.
L 2222222221 063004 012121 500.00
L 1111111111 063004 021211 500.00
An example of the record with a negative on the D column:
L 2222222221 063004 012121- 500.00
for all records. If it exists, the entire row is deleted. The procedure below
works well for this situation, BUT when there are no records with the negative
sign in the D column it deletes the first record in row 1. The Range somehow is
set for the value in the D column for row 1.
I have been unable to stop this so far.
Does anyone have a way to not delete row one if the filter is not met?
Here is the procedure:
Sub CleanCancelledChks()
Dim r As Range
With ActiveSheet
ActiveSheet.Columns("A:A").Select
Set r = .Range(.Range("D2"), .Range("D" & _
Rows.Count).End(xlUp))
.Columns("D").AutoFilter Field:=1, Criteria1:="=*-*"
Set r = r.SpecialCells(xlCellTypeVisible)
.AutoFilterMode = False
r.EntireRow.Delete
End With
End Sub
Here is 2 records as an example. The first one in the list will be deleted by
this procedure though the D column does not have a negative sign on the right
side of the value as shown in the next example below.
L 2222222221 063004 012121 500.00
L 1111111111 063004 021211 500.00
An example of the record with a negative on the D column:
L 2222222221 063004 012121- 500.00