Hello everybody
I have data in column A & B (Tourn. and Dates)
I want to use a userform to search between two dates and the results to be unique in listbox1
Hope the attachment will calrify my request
Thanks advanced
Hello everybody
I have data in column A & B (Tourn. and Dates)
I want to use a userform to search between two dates and the results to be unique in listbox1
Hope the attachment will calrify my request
Thanks advanced
Any help with that thread?
Hi Yasser,
Put this in your Userform code right under the unload code:
![]()
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 ws.Cells(j, 2) <= EDate: j = j - 1: Loop Z = ws.Range(Cells(i, 1), Cells(j, 2)): UserForm1.ListBox1.List = Z Else MsgBox "Please enter both dates" End If: End Sub
If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)
You can't do one thing. XLAdept
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin
Thanks a lot Mr. xladept for your help
I typed two dates : 1/1/2014 and 1/2/2014 and I got an error message 1004 at this line
But it works with some other dates![]()
Do Until ws.Cells(i, 2) = SDate
Another point I want unique values.. Is that possible?
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
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks