Si textbox1 contient alors rowsource Combobox1

Bonjour a tous

J'ai une petite question

je cherche le moyen de selectionner le Rowsource d'un combobox selon le contenu d'un textbox

en gros

si textbox1 contient TOTO alors rowsource Combobox1 = feuil2 ("A1:A20")

si textbox1 contient ALBATOR alors rowsource Combobox1 = feuil2 ("B1:B20") ETC..

merci de votre aide

Ton problème n'est pas assez bien présenté. As tu un Excel de test pour voir ce que tu cherches ?

Est ce que les noms Albator / Toto / .... sont inscrit en début de ligne ? A1 / B1 ... ?

Bonjour

je joint un fichier test

Merci de votre aide

Re

j'ai fait cela mais cela ne fonctionne que pour incident

Private Sub TextBox7_Change()
Set Sh = Sheets("Feuil3")
If TextBox7.Value = "INCIDENT" Then
TextBox8.List = Sh.Range("B1:B" & Sh.Range("B" & Rows.Count).End(xlUp).Row).Value
If TextBox7.Value = "ACCIDENT" Then
TextBox8.List = Sh.Range("C1:C" & Sh.Range("C" & Rows.Count).End(xlUp).Row).Value
End If
End If
End Sub

bonjour

Je crois que finalement j'ai trouvé.

Private Sub TextBox7_Change()
Set Sh = Sheets("Feuil3")
If TextBox7 = "INCIDENT" Then
TextBox8.List = Sh.Range("B1:B" & Sh.Range("B" & Rows.Count).End(xlUp).Row).Value
End If
If TextBox7 = "ACCIDENT" Then
TextBox8.List = Sh.Range("C1:C" & Sh.Range("C" & Rows.Count).End(xlUp).Row).Value
End If
End Sub

Merci

J'ai été un peu long car je travail de mon coté mais justement j'allais te répondre que ton IF était mal placé et du coup la condition ACCDIENT ne pouvait jamais arriver.

Content que tu es trouvé par toi même.

Bonjour le forum

Bonjour reinruoff, QuentinATSA

Si tu n'as qu'une seule alternative ("Incident" ou "Accident"), tu places ces items dans un ComboBox ainsi tu n'auras pas à entrer les dites valeurs dans un TextBox ...

Très peu différent, le code serait :

Private Sub ComboBox1_Change()
Set Sh = Sheets("Feuil2")

If ComboBox1.Value = "Incident" Then
ComboBox2.List = Sh.Range("A1:A" & Sh.Range("A" & Rows.Count).End(xlUp).Row).Value
ElseIf ComboBox1.Value = "Accident" Then
ComboBox2.List = Sh.Range("B1:B" & Sh.Range("B" & Rows.Count).End(xlUp).Row).Value
End If
End Sub

Private Sub UserForm_Initialize()
ComboBox1.AddItem "Incident"
ComboBox1.AddItem "Accident"
End Sub

@+ Ericcool02

Rechercher des sujets similaires à "textbox1 contient rowsource combobox1"