Announcement

Collapse
No announcement yet.

VBA Macro To AdvancedFilter Based On Year & Month Inputted

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • VBA Macro To AdvancedFilter Based On Year & Month Inputted



    Hi !!!

    Please Help me in AutoAdvance filtering the Database with the value of date

    I want to filter the entire sheet with criteria Month and days

    this wat i written
    Code:
    Sub Filter_Test()
    
        '\ update criteria values in hidden worksheet
        With Worksheets("CriteriaValues").Range("Database")
            .Cells(2, 1).Value = InputBox(prompt:="Enter Year for Filter")
            .Cells(2, 2).Value = InputBox(prompt:="Enter Month for Filter")
        End With
    
        '\ use hidden criteria range to filter data on datavalues worksheet
        Worksheets("Main").Range("Database").AdvancedFilter Action:=xlFilterInPlace, CriteriaRange _
            :=Worksheets("CriteriaValues").Range("Database"), Unique:=False
    End Sub
    Plz Help !!!!
    Attached Files
    Last edited by Dave Hawley; November 16th, 2008, 07:06.

  • #2
    Re: Filtering Database

    Revised code.

    Code:
    Sub Filter_Test()
    
        '\ update criteria values in hidden worksheet
        With Worksheets("CriteriaValues") 'adjusted: referencing a wrong named range
            .Cells(2, 1).Value = InputBox(prompt:="Enter Month for Filter") 'adjusted: Month
            .Cells(2, 2).Value = InputBox(prompt:="Enter Days for Filter") 'adjusted: Days
        End With
    
        '\ use hidden criteria range to filter data on datavalues worksheet
        Worksheets("Main ").Range("Database").AdvancedFilter _
            Action:=xlFilterInPlace, _
            CriteriaRange:=Worksheets("CriteriaValues").Range("A1").CurrentRegion, _
            Unique:=False
     ' adjusted: Main [space] (your sheet name contains a trailing space).
     ' also: CriteriaRange was referencing a wrong named range
    
    End Sub
    Since this section of the forum is paid, pay me what you find the value of these corrections. I have Paypal, please send me a PM for my e-mail address with PayPal.

    Best regards,

    Wigi
    Regards,

    Wigi

    Excel MVP 2011-2014

    For more Excel memes: visit http://www.wimgielis.com ==> English articles ==> Excel memes

    -- Topics without [CODE] tags or a meaningful topic title, will be neglected by me (and probably many others as well) --

    Comment


    • #3
      Re: Filtering Database

      Thanx dude !!!!
      Once again thanking you for ur gr8 help !!!!

      Comment


      • #4


        Re: Filtering Database

        Email me when you have paid Wigi and I'll unban you.

        Comment

        Working...
        X