+ Reply to Thread
Results 1 to 2 of 2

Filter by XX days

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    06-17-2010
    Location
    Donemana, NI
    MS-Off Ver
    Excel 2007
    Posts
    386

    Filter by XX days

    Hi,
    i am looking to filter date by user generated days, i.e an input box and they the number of + or - days so for example if today -10 was inputted the 29/12/16 would be filtered, I am currently using the below code; Can anyone help amend this?

    Sub Another_Filter1()
    Dim ws As Worksheet:    Set ws = Sheets("X47")
        
        Application.ScreenUpdating = False
        
        Application.Calculation = xlManual
        
        Application.EnableEvents = False
        
        Application.DisplayAlerts = False
    
    With ws
        .AutoFilterMode = False
        .Range("A5:AO5000").AutoFilter Field:=1, Criteria1:=Date + 1
        .Range("$A$5:$BA$5000").AutoFilter Field:=24, Criteria1:="="
    End With
    
        Application.ScreenUpdating = True
        
        Application.Calculation = xlAutomatic
        
        Application.EnableEvents = True
        
        Application.DisplayAlerts = True
    
    End Sub

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Filter by XX days

    Hi,

    One way

    Sub FilterDates()
        Dim lDt As Long, l As Long, ws As Worksheet
        Set ws = Sheets("X47")
        l = InputBox("Enter a number")
        If Not IsNumeric(l) Then
            MsgBox ("Please enter a number")
            Exit Sub
        End If
    
        lDt = DateSerial(Year(Date), Month(Date), Day(Date))
        ws.Range("$A$5:$AO$500").AutoFilter Field:=24, Criteria1:=">=" & lDt - l, Criteria2:="<=" & lDt + l
    
    End Sub
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. macro to filter to a date 2 or 3 days ago
    By Newsome79 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-03-2016, 10:42 AM
  2. VBA to filter from today's date + 4 business days
    By kop1ko in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-19-2016, 07:20 AM
  3. How to filter my data for consective days
    By trolle in forum Excel General
    Replies: 1
    Last Post: 02-08-2016, 04:15 PM
  4. Filter for working days
    By Timanjo1 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 07-07-2015, 02:35 PM
  5. [SOLVED] Create a macro to filter between today and the next 30 days
    By jonathan.haynes in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 08-05-2013, 05:08 AM
  6. Filter by various dates 30, 60, 90 days in the future
    By sandiegobeach in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 10-21-2012, 09:18 PM
  7. Average Days in filter - based on value in same row plus VBA
    By RxMiller in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 06-23-2010, 10:11 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1