Scan five columns and delete rows that don't have today's date

kelly mort

Well-known Member
Joined
Apr 10, 2017
Messages
2,169
Office Version
  1. 2016
Platform
  1. Windows
Hi,
I need a script that will scan from E4 to last used row then G4, I4, K4 and M4 for today's date. So any row which does not have today's date in the said columns, delete them.

I am stacked so I need someone pull me out.

Thanks
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Oh sure!!!


I missed something . Working very great

Thanks
 
Upvote 0
Try
Code:
Sub Del_Rows_v2()
  Dim Resp As String
  
  Resp = InputBox("Enter date of interest")
  If IsDate(Resp) Then
    Application.ScreenUpdating = False
    Range("N2").Formula = "=COUNTIF(G4:M4," & CLng(DateValue(Resp)) & ")=0"
    With Range("A3:M" & Range("A" & Rows.Count).End(xlUp).Row)
      .AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:=Range("N1:N2"), Unique:=False
      .Offset(1).EntireRow.Delete
      If .Parent.FilterMode Then .Parent.ShowAllData
    End With
    Range("N2").ClearContents
    Application.ScreenUpdating = True
  End If
End Sub


Hello sorry to wake this up

But is there a way to set date range?

Say 11-09-18 to 19-09-18 with the InputBox maybe separated by comma ?


Thanks
 
Upvote 0
But is there a way to set date range?

Say 11-09-18 to 19-09-18 with the InputBox maybe separated by comma ?
So, just keep rows that have a date anywhere in the entered date range?
 
Last edited:
Upvote 0
The success/failure of this might depend on what is in the columns in between but see how it goes.
Code:
Sub Del_Rows_v3()
  Dim Resp As String
  Dim vDates As Variant
  
  Resp = InputBox("Enter date range, separated by a comma")
  If InStr(1, Resp, ",") Then
    vDates = Split(Resp, ",")
    If IsDate(vDates(0)) And IsDate(vDates(1)) Then
      Application.ScreenUpdating = False
      Range("N2").Formula = "=COUNTIFS(G4:M4,"">=""&" & CLng(DateValue(vDates(0))) & ",G4:M4,""<=""&" & CLng(DateValue(vDates(1))) & ")=0"
      With Range("A3:M" & Range("A" & Rows.Count).End(xlUp).Row)
        .AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:=Range("N1:N2"), Unique:=False
        .Offset(1).EntireRow.Delete
        If .Parent.FilterMode Then .Parent.ShowAllData
      End With
      Range("N2").ClearContents
      Application.ScreenUpdating = True
    End If
  End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,923
Messages
6,122,289
Members
449,077
Latest member
Rkmenon

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