Delete rows Found With Autofilter

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,562
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I have a worksheet (schedule.csv) that I wish to remove all rows of data with the exception of those in which the value in column M = variable value usr_date.

The worksheet alias is ws_schedule
I wish to delete all the rows with the exception of those in which the value in column n = usr_date (19-06-19). My data has no header row

Can anyone help me with a vba solution for this?

I have this so far, but the autofilter isn't working. It comes up with no rows revealed...

Code:
With ws_schedule
        .AutoFilterMode = False
        .Rows(1).Insert shift:=xlDown
        .Range("A1:Z1").AutoFilter
        .Range("A1:Z1").AutoFilter Field:=13, Criteria1: <> usr_date
    End With
 
Last edited:

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
All the code please......we can't see what usr_date variable is, or how it is declared !!
 
Upvote 0
Code:
  With ws_schedule
    .AutoFilterMode = False
    '.Rows(1).Insert Shift:=xlDown ' what's this for?
    .Range("A1").CurrentRegion.AutoFilter Field:=13, Criteria1:="<>" & usr_date
    .AutoFilter.Range.Offset(1).EntireRow.Delete
    .AutoFilterMode = False
  End With
 
Upvote 0
Thank you shg! That was exactly what I was trying to accomplish. I couldn't get around the criteria parameter. One thing though, the filter is applied at row 1 which is part of the data, so it is excluded from the filtering. That is why I added the line that you questioned "what's this for". It inserts a blank row and the filter is applied to the blank row and thus doesn't exclude any data. A header row of sorts. A better way exists perhaps?
 
Upvote 0
Add a header row before running the macro.
 
Upvote 0

Forum statistics

Threads
1,213,526
Messages
6,114,122
Members
448,550
Latest member
CAT RG

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