Boucle avec combobox [VBA][Excel]
Résolu
Bonjour,
J'aimerais simplifier mon code car je fait plusieurs fois la même opération. J'aimerais utiliser une boucle et par la suite utiliser la macro dans un autre programme. Voici ce que j'ai fait mais ça ne fonctionne pas. Désolé, je suis nouveau dans la programmation VBA.
Voici mon code d'origine:
Private Sub CommandButton1_Click()
If ComboBox7.Value = "VENTILATEUR" Then
Range("c14").Value = "FAN" & " " & ComboBox8.Value & " " & ComboBox9.Value _
& " " & ComboBox10.Value & " " & ComboBox11.Value & " " & ComboBox12.Value & " " & ComboBox13.Value
End If
End sub
Voici ce que je veux faire:
private sub Ventilateur ()
Dim i as interger
For 8 to 13
Comboboxi.value
next i
end sub
Private Sub CommandButton1_Click()
If ComboBox7.Value = "VENTILATEUR" Then
Range("c14").Value = "FAN" & " "
Call Ventilateur
End If
End sub
Merci de votre aide
Bonne journée
J'aimerais simplifier mon code car je fait plusieurs fois la même opération. J'aimerais utiliser une boucle et par la suite utiliser la macro dans un autre programme. Voici ce que j'ai fait mais ça ne fonctionne pas. Désolé, je suis nouveau dans la programmation VBA.
Voici mon code d'origine:
Private Sub CommandButton1_Click()
If ComboBox7.Value = "VENTILATEUR" Then
Range("c14").Value = "FAN" & " " & ComboBox8.Value & " " & ComboBox9.Value _
& " " & ComboBox10.Value & " " & ComboBox11.Value & " " & ComboBox12.Value & " " & ComboBox13.Value
End If
End sub
Voici ce que je veux faire:
private sub Ventilateur ()
Dim i as interger
For 8 to 13
Comboboxi.value
next i
end sub
Private Sub CommandButton1_Click()
If ComboBox7.Value = "VENTILATEUR" Then
Range("c14").Value = "FAN" & " "
Call Ventilateur
End If
End sub
Merci de votre aide
Bonne journée
1 réponse
-
Bonjour,
Private Sub CommandButton1_Click() Dim Fans As String If ComboBox7.Value = "VENTILATEUR" Then Call Ventilateur(Fans) Range("c14").Value = "FAN" & " " & Fans End If End Sub Private Sub Ventilateur(Fans) Dim i As Integer For i = 8 To 13 Fans = Fans & " " & Me.Controls("ComboBox" & i) Next i End Sub-
-
@Slaman84Re,
Quand j'essais le code de Ventilateur(Fans)
Question: vos combobox sont dans ou sur quoi, feuille ou Userform ???? -
-
-
-