Private Sub ComboBox1_click()
TAB1 = [TAB_HFSHS].Value
Set d = CreateObject("Scripting.Dictionary")
Select Case Me.ComboBox1
Case "Finis à Chaud - EN 10 210-2"
For Each c In TAB1
temp = ""
temp = Left(c, InStrRev(c, "/") - 1)
'MsgBox temp 'OK mais pas dans le Combobox.2
Dim i As Long
Dim dic As Object
Dim tb() As Variant
Set dic = CreateObject("scripting.dictionary")
tb = Feuil1.Range("A1:A10").Value ' Modifier la source
For i = 1 To UBound(tb)
dic(Split(tb(i, 1), " /")(0)) =""
Next i
tb = dic.keys
If dic.Count > 1 Then
Me.ComboBox2.List = tb
ElseIf dic.Count = 1 Then
Me.ComboBox2.AddItem tb(0)
End If
Bonjour Le Forum, Roblochon
Merci pour votre code, je l'ai intégré dans mon fichier.
Le combobox est alimenté avec toutes les données et avec le /.
Par contre avec mon temp cela marche
temp = Left(c, InStrRev(c, "/") - 1)
mais je n'arrive pas à l'intégrer
Merci de votre Aide
Merci pour votre Aide
Voilà avec le bon Code en rouge
Private Sub ComboBox1_click()
Dim i As Long
Dim dic As Object
Dim tb() As Variant
Set dic = CreateObject("scripting.dictionary")
Select Case Me.ComboBox1
Case "Finis à Chaud - EN 10 210-2"
tb = [TAB_HFSHS].Value
For i = 1 To UBound(tb)
'dic(Split(tb(i, 1), "/ ")(0)) = "" dic(VBA.Left(tb(i, 1), InStrRev(tb(i, 1), "/") - 1)) = ""
Next i
tb = dic.keys
If dic.Count > 1 Then
Me.ComboBox2.List = tb
ElseIf dic.Count = 1 Then
Il n'y a pas besoin de tester si dic.Count = 1, ceci fonctionne dans tous les cas :
VB:
Dim dic As Object, tb, i&
Set dic = CreateObject("scripting.dictionary")
tb = Feuil1.Range("A1:A10") 'Modifier la source
For i = 1 To UBound(tb)
dic(Split(tb(i, 1), " /")(0)) = ""
Next i
ComboBox2.List = dic.keys
Bonsoir Job75.
Merci pour le code plus court et propre
Mais : dic(Split(tb(i, 1), " /")(0)) = "" ne convient pas comme indiqué plus haut
celui-ci oui : dic(VBA.Left(tb(i, 1), InStrRev(tb(i, 1), "/") - 1)) = ""