macro

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,561
Office Version
  1. 2021
Platform
  1. Windows
i have written code to delete all rows containing the following in col A from from 2 onwards

~
text containing Copy


I get a run time error 'object doesn't support this property or method" and code below is highlighted

Code:
  .AutoFilter



Code:
 Sub Delete_unwanteditems()
     With Sheets("file Names")
    
     .Range("A1").AutoFilter 1, Array("*~", "", "*copy*"), xlFilterValues

   .AutoFilter.Range.Offset(1).EntireRow.Delete
      .AutoFilter
   End With
 end Sub


See sample Data below

Macro to Delete Tilde & Text Containing Copy.xlsm
AB
1File NameDate Modified
2~$Copy Sales templates from Network.xlsm22/07/2021
3~$ECM BR1 sales Report Import Template 2021 Ver 1.1.xlsm22/07/2021
4~$B2 sales Report Import Template 2020.xlsm26/10/2020
5Copy Sales templates from Network.xlsm22/07/2021
6BR2 Sales Report Import Template 2021 Ver 1.1.xlsm22/07/2021
7BR3 Sales Report Import Template 2021 Ver 1.1.xlsm22/07/2021
8BR4 Sales Report Import Template 2021 Ver 1.1.xlsm22/07/2021
9
Sheet1


Your assistance in amending my code is most appreciated
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Use
VBA Code:
.AutoFilterMode=False
 
Upvote 0
thanks for Pointing this out Fluff

when running the Macro the list of files in Col A containing "~" and "Copy" are not being deleted in Col A

Kindly amend my code
 
Upvote 0
Hadn't noticed that you have 3 criteria, which you cannot do unless looing for exact matches. Try
VBA Code:
.Range("A1").AutoFilter 1, "*~", xlOr, "*copy*"
then after deleting the visible row run the filter again for the blanks
 
Upvote 0
Thanks for amending Code

it now deletes all the rows in Col A

i only want items containing either a Tilde ~ and tect containing Copy to be deleted


Kindly test & amend
 
Upvote 0
Forgot you need to escape the tilde
VBA Code:
.Range("A1").AutoFilter 1, "*~~*", xlOr, "*copy*"
 
Upvote 0
Solution
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,975
Messages
6,122,538
Members
449,088
Latest member
RandomExceller01

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