Results 1 to 3 of 3

Thread: Filter a Date column using VBA

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Neophyte holograful's Avatar
    Join Date
    Feb 2020
    Posts
    1
    Articles
    0
    Excel Version
    Excel 2016

    Filter a Date column using VBA

    Hi,

    I need to filter a Date column using VBA code and a text box.
    The user will type in the text box and the data will filter.

    Below is the code I am using to filter columns that contain text data, and it works as intended:
    Code:
    Private Sub textbox_PanelDate_Change()
        Dim S As String
        S = textbox_PanelDate
        If Len(S) > 0 Then
            Range("B6").AutoFilter Field:=18, Criteria1:="*" & S & "*"
        Else
            Range("B6").AutoFilter Field:=18
        End If
    End Sub

    What is the code to use to filter a column that contain date data?

    The column is formatted as short-date. See the uploaded images for reference.
    When I type in the Panel text box the spreadsheet is filtering (Panel filter.jpg).
    I expect the same result when I type in the Panel Date text box - but the result is blank cells only (Panel Date No filter.jpg).
    I use the above code for both text boxes.

    Let me know if you need more info.


    Thank you.

    Filter a Date column using VBA
    Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	Panel filter.jpg 
Views:	8 
Size:	28.9 KB 
ID:	9623   Click image for larger version. 

Name:	Panel Date No filter.jpg 
Views:	7 
Size:	14.3 KB 
ID:	9624  

Posting Permissions

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