Extract unique dates given a criteria

heyviggy

New Member
Joined
Sep 5, 2013
Messages
7
I have a long list of dates (randomly given), and want to extract unique dates after 01.01.2000 from my list using a macro. So far I got this:

Sub unikeVerdier()
Dim d As Object, c As Variant, i As Long, lr As Long
Set d = CreateObject("Scripting.Dictionary")
lr = Cells(Rows.Count, 1).End(xlUp).Row
c = ActiveWorkbook.Worksheets("Input_raw data").Range("C7:C10006" & lr)
For i = 1 To UBound(c, 1)
d(c(i, 1)) = 1
Next i
ActiveWorkbook.Worksheets("Usage interm.calc.").Range("B90").Resize(d.Count) = Application.Transpose(d.keys)
End Sub

By applying this I get all the unique values returned at B90 in my desired worksheet. The two problems I can't get around right now is:

1) How can I make the macro so the dates comes out sorted?
2) How can I exclude dates before 01.01.2000 from my list of unique values?

Best regards
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Please test this:

Code:
Sub unikeVerdier()
Dim d As Object, c, i As Long, lr&, wb As Workbook, ws As Worksheet


Set wb = ActiveWorkbook
Set ws = wb.Worksheets("Usage")
ws.Range("b89").Value = "Dates" ' header for list
Set d = CreateObject("Scripting.Dictionary")
lr = Cells(Rows.Count, 1).End(xlUp).Row
c = wb.Worksheets("Input").Range("C7:C10006" & lr)
For i = 1 To UBound(c, 1)
    d(c(i, 1)) = 1
Next


ws.Range("B90").Resize(d.Count) = Application.Transpose(d.keys)
lr = ws.Range("b" & Rows.Count).End(xlUp).Row
With ws.Sort
    .SortFields.Clear
    .SortFields.Add Key:=Range("B89"), SortOn:=xlSortOnValues, Order:=1, DataOption:=0
    .SetRange Range("B89:B" & lr)
    .Header = xlYes
    .MatchCase = False
    .Orientation = xlTopToBottom
    .SortMethod = 1
    .Apply
End With
ws.Range("d89").Value = ""
ws.Range("d90").FormulaR1C1 = "=RC[-2]>36526"   ' 36526 = 1/1/2000
ws.Range("b89:b" & lr).AdvancedFilter xlFilterInPlace, ws.Range("d89:d90"), , True


End Sub
 
Upvote 0
Worked perfectly, thank you very much! :)

One small thing though. The rows 90-91 disappears, and the row numbers in the work sheet gets blue. Is this something that can be avoided?



Please test this:

Code:
Sub unikeVerdier()
Dim d As Object, c, i As Long, lr&, wb As Workbook, ws As Worksheet


Set wb = ActiveWorkbook
Set ws = wb.Worksheets("Usage")
ws.Range("b89").Value = "Dates" ' header for list
Set d = CreateObject("Scripting.Dictionary")
lr = Cells(Rows.Count, 1).End(xlUp).Row
c = wb.Worksheets("Input").Range("C7:C10006" & lr)
For i = 1 To UBound(c, 1)
    d(c(i, 1)) = 1
Next


ws.Range("B90").Resize(d.Count) = Application.Transpose(d.keys)
lr = ws.Range("b" & Rows.Count).End(xlUp).Row
With ws.Sort
    .SortFields.Clear
    .SortFields.Add Key:=Range("B89"), SortOn:=xlSortOnValues, Order:=1, DataOption:=0
    .SetRange Range("B89:B" & lr)
    .Header = xlYes
    .MatchCase = False
    .Orientation = xlTopToBottom
    .SortMethod = 1
    .Apply
End With
ws.Range("d89").Value = ""
ws.Range("d90").FormulaR1C1 = "=RC[-2]>36526"   ' 36526 = 1/1/2000
ws.Range("b89:b" & lr).AdvancedFilter xlFilterInPlace, ws.Range("d89:d90"), , True


End Sub
 
Upvote 0
I’m glad it’s working. When advanced filter is used in place, you get the blue row numbers, indicating a filtered range.</SPAN></SPAN>
To avoid that, use the option that copies the result to another location.</SPAN></SPAN>
 
Upvote 0

Forum statistics

Threads
1,215,096
Messages
6,123,074
Members
449,093
Latest member
ripvw

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top