Macro to Delete rows where Text Not TRUE in Col D

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,563
Office Version
  1. 2021
Platform
  1. Windows
I have True or False in Col E

i have tried to write code to delete these rows and if there are any blank rows to delete these as well

I get a run time error "autofilter method of range class failed"

It would be appreciated if someone could mend my code


Sub DeleteNotTrue()
With Sheets("check List")

With Cells(1).CurrentRegion
.AutoFilter 5, "<>TRUE"""
.Offset(1).EntireRow.Delete
.AutoFilter
End With
End With

End Sub [/code]
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Hello Howard,

Changing the autofilter line a little should work:-
VBA Code:
Sub DeleteNotTrue()

Application.ScreenUpdating = False
       
        With Sheets("Check List").Cells(1).CurrentRegion
                .AutoFilter 5, "<>" & "TRUE"
                .Offset(1).EntireRow.Delete
                .AutoFilter
        End With

Application.ScreenUpdating = True

End Sub

It should also take care of the blank rows assuming that the blank cells extend into Column E as well.

I hope that this helps.

Cheerio,
vcoolio.

P.S. Check your sheet name cases as well ("check list", "Check List"?)
 
Upvote 0
Hello Howard,

I've just realised that your thread title says Column D. Your code says Column E. If need be, change the 5 to 4.

Cheerio,
vcoolio.
 
Upvote 0
Thanks for the help vcoolio

I have posted sample data on Dropbox -see link below


I posted a similar type question on Excelforum and received a reply but did not work -Even though it was a different question to do with CF , I so dont want to violate any forum rules


 
Upvote 0
Perhaps this Howard:-

VBA Code:
Sub DeleteCFitems()

Application.ScreenUpdating = False
       
        With Sheet1.Range("E1", Sheet1.Range("E" & Sheet1.Rows.Count).End(xlUp))
                .AutoFilter 1, "<>" & "TRUE"
                .Offset(1).EntireRow.Delete
                .AutoFilter
        End With

Application.ScreenUpdating = True

End Sub

BTW, I wouldn't use check boxes in this type of situation as, once rows are deleted, embedded items (such as the check boxes) will just move up on top of each other as the rows move up on deletion.

Cheerio,
vcoolio.
 
Upvote 0
You're welcome Howard. Glad to have been able to assist and thanks for the feed-back

Cheerio,
vcoolio.
 
Upvote 0

Forum statistics

Threads
1,215,063
Messages
6,122,930
Members
449,094
Latest member
teemeren

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