OVH Cloud OVH Cloud

module de classe, un raccourci?

1 réponse
Avatar
camille
Bonjour,

J'ai 45 combobox (cbo1 à cbo45). j'ai affecté à chaque changement de
combobox le code ci-dessous. Par contre, je l'ai recopié 45 fois. Cela me
fait trop de ligne car j'ai d'autres combobox à traiter aussi (cboa).
Je pense que je peux appliquer une variable de genre: For i= 1 to 45 mais
cela en marche pas avec "Private Sub cbo& i_Change()". Je vu sur excelabo
les modules de classe? Ce serait peut-être la solution? Quelqu'un peut-il
m'aider à construire ce code?

Merci d'avance
Camille

Private Sub cbo1_Change()
If CBO1 = 0 Then TXTQ1 = ""
TXTD1.text = Application.Index(Range("fichierarticles!design"),
CBO1.ListIndex + 1)
TXTP1.text = Application.Index(Range("fichierarticles!pxachat"),
CBO1.ListIndex + 1)
cboa1.text = Application.Index(Range("fichierarticles!affec"),
CBO1.ListIndex + 1)
TXTV1.text = Application.Index(Range("fichierarticles!artf"), CBO1.ListIndex
+ 1)
End Sub

Private Sub cbo2_Change()
If CBO2 = 0 Then TXTQ02 = ""
TXTD2.text = Application.Index(Range("fichierarticles!design"),
CBO2.ListIndex + 1)
TXTP2.text = Application.Index(Range("fichierarticles!pxachat"),
CBO2.ListIndex + 1)
cboa2.text = Application.Index(Range("fichierarticles!affec"),
CBO2.ListIndex + 1)
TXTV2.text = Application.Index(Range("fichierarticles!artf"), CBO2.ListIndex
+ 1)
End Sub

1 réponse

Avatar
michdenis
Bonjour Camille,

voici un exemple très simple si tes combobox sont dans une feuille de calcul
http://cjoint.com/?dpu35s4vNr

Dans le module de classe du peux écrire la macro que tu désires.

Le seul Hic, il te faudra écrire une procédure qui définira la plage
de cellule utilisée comme "Liste"


Salutations!



"camille" a écrit dans le message de news:
Bonjour,

J'ai 45 combobox (cbo1 à cbo45). j'ai affecté à chaque changement de
combobox le code ci-dessous. Par contre, je l'ai recopié 45 fois. Cela me
fait trop de ligne car j'ai d'autres combobox à traiter aussi (cboa).
Je pense que je peux appliquer une variable de genre: For i= 1 to 45 mais
cela en marche pas avec "Private Sub cbo& i_Change()". Je vu sur excelabo
les modules de classe? Ce serait peut-être la solution? Quelqu'un peut-il
m'aider à construire ce code?

Merci d'avance
Camille

Private Sub cbo1_Change()
If CBO1 = 0 Then TXTQ1 = ""
TXTD1.text = Application.Index(Range("fichierarticles!design"),
CBO1.ListIndex + 1)
TXTP1.text = Application.Index(Range("fichierarticles!pxachat"),
CBO1.ListIndex + 1)
cboa1.text = Application.Index(Range("fichierarticles!affec"),
CBO1.ListIndex + 1)
TXTV1.text = Application.Index(Range("fichierarticles!artf"), CBO1.ListIndex
+ 1)
End Sub

Private Sub cbo2_Change()
If CBO2 = 0 Then TXTQ02 = ""
TXTD2.text = Application.Index(Range("fichierarticles!design"),
CBO2.ListIndex + 1)
TXTP2.text = Application.Index(Range("fichierarticles!pxachat"),
CBO2.ListIndex + 1)
cboa2.text = Application.Index(Range("fichierarticles!affec"),
CBO2.ListIndex + 1)
TXTV2.text = Application.Index(Range("fichierarticles!artf"), CBO2.ListIndex
+ 1)
End Sub