Delect all rows that contain an Error

MarkCBB

Active Member
Joined
Apr 12, 2010
Messages
497
Hello,

I need some help completing this code.

Currently the code finds the range, fills the formula, the selects the errors (Using GoTo formulas, errors), it selects all the rows that contain the errors, but when I try to delete all those rows, it only deletes the first group on consecutive rows that contain the errors, the rest are all left there.



Sub CleanIT()
Dim FR As Range

Range("A2").Select
Range(Selection, Selection.End(xlDown)).Select
Set FR = Selection
FR.Offset(, 18).Select
Set FR = Selection
Selection.FormulaR1C1 = _
"=INDEX(OFFSET(STAFF_DB!R1C1,1,,COUNTA(STAFF_DB!C1)-1),MATCH(CLEANIT!R[128]C[-17],OFFSET(STAFF_DB!R1C2,1,,COUNTA(STAFF_DB!C2)-1),0))"
Selection.SpecialCells(xlCellTypeFormulas, 16).Select
Range(Selection, Selection.End(xlToLeft)).Select
Selection.Delete Shift:=xlUp
FR.Copy
FR.PasteSpecial Paste:=xlPasteValues
End Sub


if working correctly, this formula would delete all the rows that contain errors, in column S.

Please let me know if you require any further information regarding this, thanks
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Try

Code:
Columns("S").SpecialCells(xlCellTypeFormulas, xlErrors).EntireRow.Delete
 
Upvote 0
Thasnk again Vog,

I had to change it a little, this is what I ended on: just a fyi.
Sub CleanIT()
Dim FR As Range

Range("A2").Select
Range(Selection, Selection.End(xlDown)).Select
Set FR = Selection
FR.Offset(, 18).Select
Set FR = Selection
Selection.FormulaR1C1 = _
"=INDEX(OFFSET(STAFF_DB!R1C1,1,,COUNTA(STAFF_DB!C1)-1),MATCH(CLEANIT!R[128]C[-17],OFFSET(STAFF_DB!R1C2,1,,COUNTA(STAFF_DB!C2)-1),0))"
FR.Copy
FR.PasteSpecial Paste:=xlPasteValues
Columns("S").SpecialCells(xlCellTypeConstants, 16).EntireRow.Delete

Thanks,
 
Upvote 0

Forum statistics

Threads
1,224,527
Messages
6,179,331
Members
452,907
Latest member
Roland Deschain

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top