Sub a()
Dim critere$, col As Range
critere = Format(Date, "yyyy") & "_TR_*"
With ActiveSheet
Set col = .Columns(26).Cells 'colonne Z, à adapter
With .UsedRange.Columns(1)
.AutoFilter Field:=1, Criteria1:=critere
.SpecialCells(xlCellTypeVisible).Copy col(1)
.AutoFilter
End With
End With
If Not CStr(col(1)) Like critere Then col(1).Delete xlUp
ComboBox1.RowSource = IIf(col(1) = "", "", col.CurrentRegion.Address)
End Sub
Sub b()
Dim critere$, tablo, i&, x$, liste$(), n&
critere = Format(Date, "yyyy") & "_TR_*"
tablo = ActiveSheet.UsedRange.Columns(1).Resize(, 2) 'matrice, plus rapide, au moins 2 éléments
For i = 1 To UBound(tablo)
x = CStr(tablo(i, 1))
If x Like critere Then
ReDim Preserve liste(n)
liste(n) = x
n = n + 1
End If
Next
ComboBox1.RowSource = "" 'sécurité
If n Then ComboBox1.List = liste Else ComboBox1.Clear
End Sub
bonjourBonjour dindin, dubarre, le forum,
On parle de RowSource donc il s'agit d'une ComboBox dans un UserForm.
Voici 2 méthodes pour la remplir :
Edit : ajouté dans b ComboBox1.RowSource = "" 'sécuritéVB:Sub a() Dim critere$, col As Range critere = Format(Date, "yyyy") & "_TR_*" With ActiveSheet Set col = .Columns(26).Cells 'colonne Z, à adapter With .UsedRange.Columns(1) .AutoFilter Field:=1, Criteria1:=critere .SpecialCells(xlCellTypeVisible).Copy col(1) .AutoFilter End With End With If Not CStr(col(1)) Like critere Then col(1).Delete xlUp ComboBox1.RowSource = IIf(col(1) = "", "", col.CurrentRegion.Address) End Sub Sub b() Dim critere$, tablo, i&, x$, liste$(), n& critere = Format(Date, "yyyy") & "_TR_*" tablo = ActiveSheet.UsedRange.Columns(1).Resize(, 2) 'matrice, plus rapide, au moins 2 éléments For i = 1 To UBound(tablo) x = CStr(tablo(i, 1)) If x Like critere Then ReDim Preserve liste(n) liste(n) = x n = n + 1 End If Next ComboBox1.RowSource = "" 'sécurité If n Then ComboBox1.List = liste Else ComboBox1.Clear End Sub
A+
Alors utilisez la macro b du post #3.mon objectif c'est afficher la liste déjà filtrée dans une combo sans passer par le filtre
désolé j'ai réussi à adapter le a mais pas le bAlors utilisez la macro b du post #3.