+ Reply to Thread
Results 1 to 6 of 6

Adjust Macro To Filter Column By Date

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    07-07-2008
    Location
    sCOTLAND
    MS-Off Ver
    Office 2003 SP3
    Posts
    256

    Adjust Macro To Filter Column By Date

    I have a problem that i hope someone can help me with

    I need 2 things if possible

    I have managed to put together a drop down calendar but i am having problems getting it to work correctly. If you look at my sample sheet you will see if you click any cell in G or H columns the calendar will appear. I would like this changed so that it only appears when i click on cell D1. The date that show only shows the month of January, can we change that to show all months.

    Also when i select a date to go in to D1 i would like to add a filter on Colums I, so if i select any date it will filter out any rows from A-Y that are older than that date.

    Is this possible?
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: Adjust Macro To Filter Column By Date

    Try this...

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        'The 1st method is coded to launch when a curtain cell is  selected
        If Target(1).Address(0, 0) = "D1" Then
            CalendarFrm.Show
        End If
    End Sub
    
    Private Sub Worksheet_Change(ByVal Target As Range)
        If Target(1).Address(0, 0) = "D1" Then
            Application.ScreenUpdating = False
            Me.AutoFilterMode = False
            If IsDate(Target(1).Value) Then
                Range("A3:Y" & Range("I" & Rows.Count).End(xlUp).Row).AutoFilter Field:=9, Criteria1:="<=" & Target(1).Value
            End If
            Application.ScreenUpdating = True
        End If
    End Sub

  3. #3
    Forum Contributor
    Join Date
    07-07-2008
    Location
    sCOTLAND
    MS-Off Ver
    Office 2003 SP3
    Posts
    256

    Re: Adjust Macro To Filter Column By Date

    Hi Thanks for that, the Calendar is now in the right place but, it still has only January as a month, also when i put a date in it looks like it is filtering the wrong way, instead of filtering the older dates it seem to be filtering the newer dates

    I f i add a date of lets say 01/01/13, and in the I column i have dates 01/01/12 & 01/01/14, it is taking the 01/01/14 away and leaving 01/01/12. I need this to work the other way please

    Many Thanks

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: Adjust Macro To Filter Column By Date

    Quote Originally Posted by JimmiOO View Post
    but, it still has only January as a month,
    I don't understand this part. Your calendar shows all months for me.

  5. #5
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: Adjust Macro To Filter Column By Date

    Quote Originally Posted by JimmiOO View Post
    Also when i select a date to go in to D1 i would like to add a filter on Colums I, so if i select any date it will filter out any rows from A-Y that are older than that date.
    So you want the oppisite???

    If yes, change this...
    Criteria1:="<="

    To this...
    Criteria1:=">="

  6. #6
    Forum Contributor
    Join Date
    07-07-2008
    Location
    sCOTLAND
    MS-Off Ver
    Office 2003 SP3
    Posts
    256

    Re: Adjust Macro To Filter Column By Date

    Thanks very much for this, the filter is now working 100%

    I do not know why it is only showing January for me, it does show the 12 entries but all say January. We probably can't do much with this, so again thanks alot, Problem Solved

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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