+ Reply to Thread
Results 1 to 2 of 2

Applying Date ranges to Filters within Macro

  1. #1
    Registered User
    Join Date
    09-17-2014
    Location
    Cambridge, England
    MS-Off Ver
    2016
    Posts
    58

    Applying Date ranges to Filters within Macro

    Hello,

    I need to add a Macro into a workbook to allow users to filter various data down to date ranges. The users have a couple of drop down boxes to put a From and a To date into Excel. I then want to give them a button to press to apply a filter to the date and display just data that is dated on and between the to a from dates that I have allowed them to select.

    I have written my Marco and it works for a single date, but I do not know how to amend it so that it applies to all dates that are between the two date ranges.

    Currently it only works if both teh 'To' and the 'From' dates are the same...

    This is the VBA so far, quite simple and I am sure an amendment to it is simple also, I am just not sure what it is to do it, so hopefully someone can advise....

    Dim fromDate As String
    Dim toDate As String
    Dim userName As String
    Dim ptype As String


    LR = Range("A" & Rows.Count).End(xlUp).Row

    fromDate = Range("A3").Value
    toDate = Range("A4").Value
    userName = Range("A5").Value
    ptype = Range("A6").Value

    If ActiveSheet.AutoFilterMode = True Then ActiveSheet.AutoFilterMode = False

    Rows("10:10").Select
    Selection.AutoFilter
    ActiveSheet.Range("$A$10:$O$" & LR).AutoFilter Field:=1, Criteria1:=fromDate
    ActiveSheet.Range("$A$10:$O$" & LR).AutoFilter Field:=2, Criteria1:=toDate
    ActiveSheet.Range("$A$10:$O$" & LR).AutoFilter Field:=5, Criteria1:=userName
    ActiveSheet.Range("$A$10:$O$" & LR).AutoFilter Field:=6, Criteria1:=ptype



    Apologies - My browser is not behaving today and has not given me the full web content - hence why my code is not in Code Brackets.
    Last edited by sx200n; 05-14-2019 at 07:48 AM.

  2. #2
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    365 Pro Plus
    Posts
    2,274

    Re: Applying Date ranges to Filters within Macro

    Possibly swapping this code
    Please Login or Register  to view this content.
    out for this
    Please Login or Register  to view this content.
    Last edited by dangelor; 05-19-2019 at 06:37 PM.

+ 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. Applying Filters to multiple Pivot Tables
    By TommyG85 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-13-2017, 02:12 PM
  2. [SOLVED] Applying formula while using filters
    By fahadmohsin in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 11-23-2016, 07:36 AM
  3. Pivot table applying filters
    By pdalal in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-13-2015, 08:28 AM
  4. Help needed for applying two filters to pivot using vba
    By winfang in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-06-2014, 02:34 AM
  5. [SOLVED] Applying filters to Timeline Chart
    By Kausch in forum Excel General
    Replies: 2
    Last Post: 07-30-2014, 06:25 AM
  6. [SOLVED] How to get correct values without applying filters
    By SunOffice in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 11-24-2013, 06:30 PM
  7. Applying filters
    By jimz in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-14-2011, 07:49 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