Wednesday, July 13, 2016

Filtering Between Two Specific Dates In Excel

Filling Combobox With Uniqe And Ascending Order Dates

            We ago have  created combo boxes containing  dates that unique ascending order sorted . For this process we have used Ado Connection. The dates in Column B were populated into two combo boxes.

             Later we've done filtering by the selected dates from drop-down lists with buttons.

We have added the following code to enter only date (as "") in the Column B :

Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng1 As Range, rng2 As Range
      If Intersect(Target, Range("B:B")) Is Nothing Then Exit Sub
    If Target.Address = "$B$1" Then Exit Sub
    For Each rng2 In Range(Target.Address)
    If rng2.Value = "" Then
    MsgBox "You Must Enter A Valid Date (20.10.2015 etc.)", vbCritical, ""
    Exit Sub
    End If
        If IsDate(rng2.Value) = False Then
         rng2 = Empty
        Exit Sub
            rng2.Value = CDate(rng2)
        End If
    Next rng2
End Sub

No comments:

Post a Comment