XL 2016 Boucle avec optionbutton

poussy67

XLDnaute Occasionnel
Bonjour Le forum
Comme je ne suis pas un expert en vba je vais fait
appelle au pro d'Excel. :(

J'essaye de simplifier une action sans résultat de faire une boucle avec des OptionButton.
J'ai 20 optionbutton si une est cocher elle doit additionné +1 sur une
valeur déjà existante selon le choix d'un combobox lors de la validation.

En vous remerciant d'avance pour votre coup de pouce;)



Exemple:
If Val_Creneau_1 = True Then
Sheets("Horaire_Grille").Cells(ComboBox4.ListIndex + 47, 2).Value = Sheets("Horaire_Grille").Cells(ComboBox4.ListIndex + 47, 2).Value + 1
End If
If Val_Creneau_2 = True Then
Sheets("Horaire_Grille").Cells(ComboBox4.ListIndex + 47, 3).Value = Sheets("Horaire_Grille").Cells(ComboBox4.ListIndex + 47, 3).Value + 1
End If
If Val_Creneau_3 = True Then
Sheets("Horaire_Grille").Cells(ComboBox4.ListIndex + 47, 4).Value = Sheets("Horaire_Grille").Cells(ComboBox4.ListIndex + 47, 4).Value + 1
End If
If Val_Creneau_4 = True Then
Sheets("Horaire_Grille").Cells(ComboBox4.ListIndex + 47, 5).Value = Sheets("Horaire_Grille").Cells(ComboBox4.ListIndex + 47, 5).Value + 1
End If
If Val_Creneau_5 = True Then
Sheets("Horaire_Grille").Cells(ComboBox4.ListIndex + 47, 6).Value = Sheets("Horaire_Grille").Cells(ComboBox4.ListIndex + 47, 6).Value + 1
End If
If Val_Creneau_6 = True Then
Sheets("Horaire_Grille").Cells(ComboBox4.ListIndex + 47, 7).Value = Sheets("Horaire_Grille").Cells(ComboBox4.ListIndex + 47, 7).Value + 1
End If

Cdt Poussy
 

Jacky67

XLDnaute Barbatruc
Bonjour à tous
Cela pourrait ressembler à ceci

VB:
With Sheets("Horaire_Grille")
For i = 1 To 20
If Controls("Val_Creneau_" & i) Then .Cells(ComboBox4.ListIndex + 47, i + 1).Value = .Cells(ComboBox4.ListIndex + 47, i + 1).Value + 1
Next
End With

Non testé à defaut de classeur avec l'userform
 
Dernière édition:

Discussions similaires

Statistiques des forums

Discussions
311 705
Messages
2 081 729
Membres
101 806
dernier inscrit
Nebnefers