Hi Yasser,
Thanks for the rep!
Try this:
Private Sub CommandButton3_Click(): Dim i As Long, j As Long, ws As Worksheet, Z
If IsDate(UserForm1.TextDate1) And IsDate(UserForm1.TextDate2) Then
Set ws = ActiveSheet: SDate = CDate(UserForm1.TextDate1): EDate = CDate(UserForm1.TextDate2)
i = 2: Do Until ws.Cells(i, 2) >= SDate: i = i + 1: Loop
j = ws.Range("B" & Rows.Count).End(xlUp).Row
Do Until j = 1 Or ws.Cells(j, 2) <= EDate: j = j - 1: Loop
If j = 1 Then
MsgBox "Date range does not exist in this data": Exit Sub: End If
With ws.Range(Cells(i, 1), Cells(j, 2))
.AdvancedFilter Action:=xlFilterInPlace, Unique:=True
Z = ws.Range(Cells(i, 1), Cells(j, 2)).SpecialCells(xlCellTypeVisible)
UserForm1.ListBox1.List = Z: ws.Rows.Hidden = False: End With
Else
MsgBox "Please enter both dates"
End If: End Sub
Bookmarks