Deleting rows in a filtered set with For Each

James Snyder

Well-known Member
Joined
Jan 11, 2013
Messages
618
I am working on solving a problem where I get every other row deleted instead of every row. The situation is that I am using Autofilter to find empty cells in a column that shouldn't have empty cells. Before I can delete them, I need to add them to an array for exceptions handling. This means I need to step through the filtered range and record each unique ID for followup, then delete them. If I delete as I go, the "For Each" doesn't work on the original rows, but works on an increment. This means a deleted row causes the range to shift up one, and I end up deleting every other row.

I know I can solve this by deleting separately from recording them, but am searching for a way to work with the "For Each" maybe using a "Step -1" or something similar. Does anyone have any ideas?
 
Sorry - I meant no need to loop to delete them (after processing with your for each loop)
 
Upvote 0

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Thanks Mike! The need to record the duplicate rows is to be able to fix them upstream so the process can be repeated with valid data. When everything is fixed, this becomes an FTP file to the client.
 
Upvote 0
You're welcome.

Pleased to have helped solve your problem.

Good luck with your project.
 
Upvote 0

Forum statistics

Threads
1,215,758
Messages
6,126,697
Members
449,331
Latest member
smckenzie2016

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