1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
| Sub ListeDate()
Dim i%, v$, dPlg, oCel As Range, oPlg As Range
Dim dic As Object, LastLg As Integer
Dim fCel As String
Set dic = CreateObject("Scripting.Dictionary")
With Sheets("feuil2")
LastLg = .Range("A" & .Rows.Count).End(xlUp).Row
MsgBox "LastLg = " & LastLg
Set oPlg = .Range("A1:A" & LastLg) 'plage de données
End With
dPlg = oPlg.Value
'-- Tri
With oPlg.Parent.Sort
.SortFields.Clear
.SortFields.Add Key:=oPlg.Range("A1"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
.SetRange oPlg
.Header = xlNo 'xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.Apply
End With
On Error Resume Next
'-- Récupérer les dates sans doublons
For Each oCel In oPlg.Cells
fCel = Trim(Format(oCel.Value, "dd/mm/yyyy"))
If Not dic.Exists(fCel) Then
'MsgBox "oCel = " & oCel & vbCrLf & _
' "Format(" & oCel.Value & ", dd/mm/yyyy) = " & Format(oCel.Value, "dd/mm/yyyy")
dic.Add fCel, fCel
End If
Next oCel
oPlg.Value = dPlg
Set oPlg = Nothing
Erase dPlg
On Error GoTo 0
Sheets("feuil2").Range("B2").Resize(dic.Count, 1) = Application.Transpose(dic.keys)
'-- Plage nommée
ActiveWorkbook.Names.Add Name:="MaListe", RefersTo:="=Feuil2!$B$2:$B$" & LastLg & ""
'---------
With [F2].Validation
.Delete
.Add Type:=xlValidateList, Formula1:="=MaListe"
.IgnoreBlank = True
.InCellDropdown = True
'.InputTitle = ""
'.ErrorTitle = ""
'.InputMessage = ""
'.ErrorMessage = ""
'.ShowInput = True
.ShowError = True
End With
End Sub |
Partager