Delete all dates greater than a date I specify in different worksheet but same workbook.

rharri1972

Board Regular
Joined
Nov 12, 2021
Messages
132
Office Version
  1. 2019
Platform
  1. Windows
Hello! Hoping to get help from anyone gracious enough to help.
Here is my dilemma.
I have two worksheets in a workbook.
"INSTRUCTIONS" and "REPORT"
I will specify a certain date in INSTRUCTIONS
when i hit the button to control the macro's I am needing code to look through column D in "REPORTS" starting at ROW4 to the end and if the date in column D is greater than specified in INSTRUCTIONS Q2 then delete that entire row.
Example... date specified is 12/6/2021... I have dates going all the way to March of 2022 in Column D on worksheet ("REPORT"). I need any date greater than 12/6/2021 to be deleted. Well that entire row deleted. I know i have talked in circles and I apologize.
Can or will anyone help please?
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
This could be a solution for you. The macro can be pasted in a standard module and then be associated to your control button.
VBA Code:
Option Explicit
Sub DeleteRowsByDate()
    Dim lr     As Long
    Dim rw     As Long
    With Sheets("REPORT")
        lr = .Range("D" & Rows.Count).End(xlUp).Row
        For rw = lr To 4 Step -1
            If .Cells(rw, "D").Value > Sheets("INSTRUCTIONS").Range("Q2").Value Then
                .Rows(rw).Delete Shift:=xlUp
            End If
        Next rw
    End With
End Sub
 
Upvote 0
Solution
Hi & welcome to MrExcel!

Another macro to try ...
VBA Code:
Sub rharri1972()
    Dim Dt As Long, Lr As Long
    Dt = Sheets("instructions").Range("Q2").Value2
    With Sheets("reports")
        Lr = .Cells(.Rows.Count, "D").End(xlUp).Row
        .Range("D3:D" & Lr).AutoFilter Field:=1, Criteria1:=">" & Dt
        .Range("D4:D" & Lr).SpecialCells(xlVisible).EntireRow.Delete
        .AutoFilterMode = False
    End With
End Sub
 
Upvote 0
This could be a solution for you. The macro can be pasted in a standard module and then be associated to your control button.
VBA Code:
Option Explicit
Sub DeleteRowsByDate()
    Dim lr     As Long
    Dim rw     As Long
    With Sheets("REPORT")
        lr = .Range("D" & Rows.Count).End(xlUp).Row
        For rw = lr To 4 Step -1
            If .Cells(rw, "D").Value > Sheets("INSTRUCTIONS").Range("Q2").Value Then
                .Rows(rw).Delete Shift:=xlUp
            End If
        Next rw
    End With
End Sub
This worked! Thank you so much for your help!!!
 
Upvote 0
Glad having been of some help(y)but I would like to point out that GWteB 's macro is faster if you have to handle a large amount of rows.
 
Upvote 0
Glad having been of some help(y)but I would like to point out that GWteB 's macro is faster if you have to handle a large amount of rows.
Thank you for that info however, my data should not go past 2000 rows ever so i think we will be ok.
 
Upvote 0

Forum statistics

Threads
1,214,825
Messages
6,121,788
Members
449,049
Latest member
greyangel23

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