+ Reply to Thread
Results 1 to 4 of 4

Filtering Macro

Hybrid View

  1. #1
    Registered User
    Join Date
    08-11-2011
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    93

    Filtering Macro

    Hi,

    My macro selects the data (date between last month) for last month, however as I rerun the macro in next month, i have to change the code, Can you create such code which gets automatically updated as per the date.

    Note: I run the macro 1st of each month so I need to filter the data for last month.

    Thanks!
    Sandeep
    Attached Files Attached Files

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Filtering Macro

    Hi, Sandeep,

    works for me:
    Sub Filter_Macro()
    '
    ' Filter_Macro Macro
    '
    
    '
        Selection.AutoFilter
        ActiveSheet.Range("$A$1:$B$20").AutoFilter _
            Field:=1, _
            Criteria1:=">=" & CLng(DateSerial(Year(Date), Month(Date) - 1, 1)), _
            Operator:=xlAnd, _
            Criteria2:="<=" & CLng(DateSerial(Year(Date), Month(Date), 0))
    End Sub
    As long as the range will always be the same...

    Otherwise maybe better apply UsedRange for the range to filter.

    Ciao,
    Holger

  3. #3
    Registered User
    Join Date
    08-11-2011
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    93

    Re: Filtering Macro

    Oh! Thant worked fine, thank you so much for all your help, I appreciate that.

  4. #4
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: Filtering Macro

    @ sandiptemkar

    Based on your last post it seems that you are satisfied with the solution(s) you've received but you haven't marked your thread as SOLVED. I'll do that for you now but please keep in mind for your future threads that Rule #9 requires you to do that yourself. If your problem has not been solved you can use Thread Tools (located above your first post) and choose "Mark this thread as unsolved".
    Thanks.

    Also, as a new member of the forum, you may not be aware that you can thank those who have helped you by clicking the small star icon located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of those who helped.

+ 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