Consulting

Results 1 to 4 of 4

Thread: Filtering by InputBox date entries and using Autofilter with 3 criteria

  1. #1
    VBAX Regular
    Joined
    Oct 2013
    Location
    Zurich
    Posts
    14
    Location

    Filtering by InputBox date entries and using Autofilter with 3 criteria

    Hi everyone,

    I could use some help with a macro which filters a column of dates based on two dates that the user enters OR if the cell is empty.

    This is what I have so far:

    Sub CPT_Macro()
    
    
    Dim lngStart As Long, lngEnd As Long
    lngStart = InputBox("Enter stard date of interest")
    lngEnd = InputBox("Enter end date of interest")
        Range("AH7:AH8000").AutoFilter field:=1, _
            Criteria1:=">=" & lngStart, _
            Operator:=xlAnd, _
            Criteria2:="<=" & lngEnd
            Operator:=xlOr, _
            Criteria3:=""
            
    End Sub
    There seem to be two problems:
    1. I get a Type mismatch error as soon as I enter the start date (using dd.mm.yyyy, if that matters)
    2. The two lines starting with "Operator:=xlOr, _" are red (maybe I cant autofilter with xlOr?)

    I hope someone smarter can figure this out - thanks a lot!
    Viktor

  2. #2
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    hi.

    1. yes. try:
    Application.InputBox(prompt:="Enter stard date of interest", Type:=1)
    2. delete Operator:=xlOr, Criteria3:="" bit.

    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  3. #3
    VBAX Regular
    Joined
    Oct 2013
    Location
    Zurich
    Posts
    14
    Location
    1. Thanks mancubus, that works!

    2. What could I do to include the blank cells as well?

  4. #4
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    you're welcome.

    record a macro while you are manually filtering with your criteria and post the recorded macro here.
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

Tags for this Thread

Posting Permissions

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