VBA - Delete rows with certain data

ChrisFoster

Active Member
Joined
Jun 21, 2019
Messages
256
Office Version
  1. 365
Platform
  1. Windows
Hi all,

I have some coding that I have developed over time - but I'm stuck at one particular point.

In 'column B' I have a list of dates, they are all in the same format (UK). What I want is some coding that deletes any row that has a date from the current year (I'll be using this code going into next year so ideally the code will already know what year it currently is rather than just using '2019').

Please can someone help me?

Kind Regards,

Chris
 
Here's another way to try:

Code:
Sub delYear()
    With Range("B1:B" & Cells(Rows.count, "B").End(xlUp).Row)
        .AutoFilter Field:=1, Criteria1:=xlFilterThisYear, Operator:=xlFilterDynamic
        On Error Resume Next
        .Offset(1).SpecialCells(xlCellTypeVisible).EntireRow.Delete
        On Error GoTo 0
        .AutoFilter
    End With
End Sub
 
Upvote 0

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Did you use the exact same code or you change something, maybe the range?
I'm curious because you said earlier you need to change .AutoFilter Field:=1 to .AutoFilter Field:=2

You absolute legend!

When I change the autofilter field from 1 to 2 that works perfectly.

Thank you so much!
 
Upvote 0
You're welcome, glad to help, & thanks for the feedback.:)
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,906
Members
452,366
Latest member
TePunaBloke

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