Delete any rows with a date before 04/01/2016

VBAProIWish

Well-known Member
Joined
Jul 6, 2009
Messages
1,027
Office Version
  1. 365
Platform
  1. Windows
Hello All,

I have this simple macro below which works great for deleting rows with text and numbers, but doesn't work when trying to delete any row in the "Date" column that is prior to 04/01/2016. I'm sure there's some easy fix but I just can't figure it out.

VBA Code:
Sub Delete_rows_before_04_01_2016()
Dim nCol As Long
Dim cCol As Long
Dim rCount As Long

    With ActiveSheet
        nCol = Application.Match("Date", .Rows(1), 0)
        cCol = Application.Match("Customer Number", .Rows(1), 0)

        For rCount = Cells(.Rows.Count, cCol).End(xlUp).Row To 2 Step -1
            Select Case .Cells(rCount, nCol).Value
                Case Is < "04/01/2016"
                    .Rows(rCount).EntireRow.Delete
            End Select
        Next
    End With
End Sub

Thanks for anything anyone can do to get this working
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
There is an easy fix.

I hope that you can see what I have done, treated the date as a Long type.

VBA Code:
Sub Delete_rows_before_04_01_2016()
Dim nCol As Long
Dim cCol As Long
Dim rCount As Long
Dim dteDate As Long
    
    dteDate = DateSerial(2016, 1, 4)

    With ActiveSheet
    
        nCol = Application.Match("Date", .Rows(1), 0)
        cCol = Application.Match("Customer Number", .Rows(1), 0)

        For rCount = Cells(.Rows.Count, cCol).End(xlUp).Row To 2 Step -1
            Select Case .Cells(rCount, nCol).Value
                Case Is < dteDate
                   .Rows(rCount).EntireRow.Delete
            End Select
        Next
        
    End With
    
End Sub
 
Upvote 1
Solution

Forum statistics

Threads
1,224,522
Messages
6,179,292
Members
452,902
Latest member
Knuddeluff

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