Filter column between 2 dates from cells in differnt sheet

kayibey

New Member
Joined
Sep 6, 2022
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hi All,

My first post here and a novice at VBA. Please can you help me with this.

1. I have a sheet called "Control", in that sheet I have a 'starting date' in cell "K2" (01/04/2022) in DD/MM/YYYY format and 'ending date' in cell "K3"
2. I have a set of data in another sheet called "Data Q" between Columns "A" to "J", around 9000 rows.
3. I am trying to filter "Data Q" column "J" using the date range from the 2 cells mentioned in point 1

Please help :)
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
If you didn't want to use Advanced Filters, here's a VBA solution that assumes your sheet "Data Q" has headers in row 1, data starting from row 2.

VBA Code:
Option Explicit
Sub Between_Dates()
    Dim ws1 As Worksheet, ws2 As Worksheet
    Dim StartDate As Date, EndDate As Date
    Set ws1 = Worksheets("Control")
    Set ws2 = Worksheets("Data Q")
   
    StartDate = ws1.Range("K2").Value2
    EndDate = ws1.Range("K3").Value2
   
    With ws2.Range("J:J")
        .AutoFilter 1, ">=" & CLng(StartDate), 1, "<=" & CLng(EndDate)
    End With
   
End Sub
 
Upvote 0
Solution
If you didn't want to use Advanced Filters, here's a VBA solution that assumes your sheet "Data Q" has headers in row 1, data starting from row 2.

VBA Code:
Option Explicit
Sub Between_Dates()
    Dim ws1 As Worksheet, ws2 As Worksheet
    Dim StartDate As Date, EndDate As Date
    Set ws1 = Worksheets("Control")
    Set ws2 = Worksheets("Data Q")
  
    StartDate = ws1.Range("K2").Value2
    EndDate = ws1.Range("K3").Value2
  
    With ws2.Range("J:J")
        .AutoFilter 1, ">=" & CLng(StartDate), 1, "<=" & CLng(EndDate)
    End With
  
End Sub
And as simple as that. Brilliant. You are a legend. Thank you
 
Upvote 0

Forum statistics

Threads
1,214,943
Messages
6,122,380
Members
449,080
Latest member
Armadillos

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