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

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
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,214,879
Messages
6,122,065
Members
449,064
Latest member
scottdog129

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