Consulting

Results 1 to 3 of 3

Thread: VBA Filter problem

  1. #1

    VBA Filter problem

    Hi,

    I have a column that contains dates in long date format, for instance: "Tuesday, November 17, 2015".
    Also new dates are added everyday.
    Each Friday I want macro to show me (to automatically filter) results for next Monday. So let's say this Friday I want it to filter for Monday, Nov. 23.
    Firstly I have a filter for next week and then I want to filter again with criteria that is the word "Monday".

    I wrote this code but it does not work, nothing is showing, only blank column with filter on.


          Dim Datef As String
    Datef = "Monday" 
    ActiveSheet.Range("F:F").AutoFilter Field:=1, Criteria1:=xlFilterNextWeek, Operator:=xlAnd, Criteria2:="=*Datef*", Operator:=xFilterValues
    DropDown = True
    Could you help me with this issue?

  2. #2
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    forget the Datef and such and try:
    lDate = CLng(Date + 8 - Weekday(Date, 2))
    ActiveSheet.Range("F:F").AutoFilter Field:=1, Criteria1:=">=" & lDate, Operator:=xlAnd, Criteria2:="<" & lDate + 1
    Dates can be very problematic, especially if they're not using a standard formatting on your sheet.

    ref: look at the section headed FILTER BY EXACT DATE here: http://www.ozgrid.com/VBA/autofilter-vba-dates.htm
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  3. #3
    Thank you, I'll check this out

Posting Permissions

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