Delete using Filter

amerifax

Board Regular
Joined
Dec 17, 2008
Messages
247
I have many records in around 20% have an "x" in a column. I want to delete all the records that have an "X" in a column called Dup. so I used "Sort & Filter" displaying only the records that had an "X" in the Dup column. I'm sure you know what happened. I deleted even records that did not have an "X". So obviously, the filter did not work as I assumed it would.

What am I missing?
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Try:

Filter

Press F5, click Special, check Visible cells only, click OK

Press Delete
 
Upvote 0
What is the range of table headers? For instance, A1: F1.
 
Upvote 0
>>Sektor<<
AC2:AC200746 Contains many records that are marked for deletion by indicating with an "X".
Thanks
Bob
 
Upvote 0
Code:
Sub RemoveAllXs()

    Dim rng As Range
    
    With Range("AC1")
        .AutoFilter Field:=1, Criteria1:="X"
        Set rng = Range("AC2:AC200746").SpecialCells(xlCellTypeVisible)
        If Not rng Is Nothing Then
            rng.EntireRow.Delete
        End If
        .AutoFilter 'Remove filter.
    End With

End Sub
 
Upvote 0
>>VoG<<

I would think I would first set the filter. As I did before, showing only the records that have the "X". And if I have this right. I would then use F5 set the range, then go into special and select visible cells only. Then highlight the far left column and delete by rowes.

Dragging the far left column to Mark is a bit of a pain. Is there a better way to activate a select delete.

Thanks Bob

>>Sektor<<
I think you have answered my question. I will run this in the morning.
Thanks
Bob
 
Last edited:
Upvote 0
Sektor,

I wanted to clarify a few things before I ran this code. Looking at the code it seems geared towards the column and I know I gave you that impression. There is another dynamic to the data I didn't mention. The full data file is actually made up of two files. The top half is 11.3 and the bottom half is 4.3. I only want to delete the rows marked with an "X" for the 4.3 records.

This might be all you need to consider:
4.3 Data - A100917:AD200746

Addition Info you might Need:
These are my ranges:
Header Row - A1:AD1
Full Data - A2:AD200746
11.3 Data - A2:AD100916
4.3/11.3 ID - AA
DUP - AC

I'm not sure how much if any this might change the code, but I thought I should clarify this before running.

Thanks for all your help so far!

Bob
 
Last edited:
Upvote 0
Try:

Filter

Press F5, click Special, check Visible cells only, click OK

Press Delete

This works for us, but we can only delete about 500 records at a time and we are dealing with about 1,000,000 records overall.

We also tried the code from Sektor, but it didn't work quite right, I think due to the range used.

I think there may be something simple we are missing.

Bob
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,761
Members
452,940
Latest member
rootytrip

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