modified code filter data based on two dates and name

leap out

Active Member
Joined
Dec 4, 2020
Messages
271
Office Version
  1. 2016
  2. 2010
hello

first of all I would thank Mr. Fluff for this code ,and I would modified by add some condition to the code to filter data based on two dates and name

the code should filter data based on tow dates and name ,now I have names in column d and the search for names in cell m2 if b i search about name without dates then brings the data is relating the name and if I search name and two dates together then bring data for the name locates between two dates

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   Dim StartDate As Date
   Dim EndDate As Date
  
   If Target.CountLarge > 1 Then Exit Sub
   If Not Intersect(Target, Range("K2:L2")) Is Nothing Then
      If Target.Value = "" Then
         ActiveSheet.Range("A1:h1").AutoFilter Field:=1
      Else
         StartDate = Range("k2").Value
         EndDate = Range("l2").Value
         ActiveSheet.Range("A1:h1").AutoFilter Field:=1, Criteria1:=">=" & CDbl(StartDate), Operator:=xlAnd, Criteria2:="<=" & CDbl(EndDate)
      End If
   End If
End Sub

thanks
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Hi Leap Out, I don't know if you ever solved this, but I would start by replacing CDbl(StartDate) and CDbl(EndDate) just StartDate and EndDate. CDbl() is used to double a value, something you definitely don't want to do when creating a date filter.
 
Upvote 0
@PrizeGotti CDbl does not double the value, it converts a value into a double data type.
 
Upvote 0

Forum statistics

Threads
1,214,875
Messages
6,122,047
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