Consulting

Results 1 to 3 of 3

Thread: Problem with Autifilter Date Range

  1. #1
    VBAX Contributor
    Joined
    Sep 2007
    Posts
    119
    Location

    Problem with Autifilter Date Range

    I am having problem of autofilter the data for date range between date value under cell M1 and N1 input via textbox in userform.

    The date appeared in cell M1 & N1 does not same as in textbox input and the autofilter date does not filter the date as expected.

    Please help me out.

  2. #2
    VBAX Mentor
    Joined
    Dec 2008
    Posts
    404
    Location
    I think, that dates in columns L are no dates. They are the text. They only look like dates. There is effect of import of data from other base (probably).
    Before You run [Search Date], you must "translate" text on dates.
    1. Select data in column L.
    2. From menu select Data/Text to columns... (sorry, I have polish version) )

    3. In first step select "divided" and no [Next], but [End]


    Several errors are in procedure cmdSearch_Click.
    My proposal:

    Sub cmdSearch_Click()
    Dim dDatestart As Date
    Dim dDatelast As Date
    Dim ldatelast As Long
    Dim lDatestart As Long
    With Sheets("wdnsse")
        .AutoFilterMode = False
        .Cells(1, 13).Value = frmsearch.tbstartdate.Value
        .Cells(1, 14).Value = frmsearch.tbenddate.Value
        dDatestart = .Range("M1")
        dDatelast = .Range("N1")
        lDatestart = DateSerial(Year(dDatestart), Month(dDatestart), Day(dDatestart))
        ldatelast = DateSerial(Year(dDatelast), Month(dDatelast), Day(dDatelast))
        .Range("L2").AutoFilter Field:=12, _
        Criteria1:=">=" & lDatestart, _
        Operator:=xlAnd, _
        Criteria2:="<=" & ldatelast
    End With
    End Sub
    This procedure is not optimum and no error handling.

    Artik
    Last edited by Artik; 01-01-2009 at 05:27 PM.

  3. #3
    VBAX Contributor
    Joined
    Sep 2007
    Posts
    119
    Location
    Thanks Artik for your solution, its working fine now.

    Appreciate your assistance.


    Thank you

Posting Permissions

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