Avatar of Lawrence Salvucci
Lawrence Salvucci
Flag for United States of America asked on

Delete Rows where current month is found in column A

I need to be able to delete all rows where the date in column A is within the range in cell R2 & S2.

R2 = Start Date
S2 = End Date

I need to be able to do this via VBA code.
Microsoft Excel

Avatar of undefined
Last Comment
Martin Liss

8/22/2022 - Mon
Martin Liss

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question

You can do this with this code:

Sub DeleteRows()

    Dim lstrow As Long
    Dim x As Long
    CheckDate = DateSerial(Year(Now), Month(Now), 1)
    lstrow = Cells(Rows.Count, 1).End(xlUp).Row

    For x = lstrow To 3 Step -1
        If Cells(x, 1).Value < Range("R2") Or Cells(x, 1) > Range("S2") Then
        End If

End Sub

Open in new window

Lawrence Salvucci

How do I specify a specific sheet in my workbook in case I want to run this from another file or if I'm on a different sheet within that workbook?

lngLastRow = ActiveSheet.UsedRange.Rows.Count
Martin Liss

lngLastRow = Sheets("Sheet1").UsedRange.Rows.Count
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
Lawrence Salvucci

Thanks for the help! Much appreciated!
Martin Liss

You're welcome and I'm glad I was able to help.

Marty - MVP 2009 to 2012

@lsalvucci: did you at least tryed my code?!?
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Martin Liss

This line

If Cells(x, 1).Value < Range("R2") Or Cells(x, 1) > Range("S2") Then

would have deleted only dates outside of the range.