Ajout a des colonnes sous une condition

Fermé
wakafa Messages postés 40 Date d'inscription mercredi 22 juillet 2015 Statut Membre Dernière intervention 7 décembre 2020 - Modifié par wakafa le 4/08/2015 à 10:29
f894009 Messages postés 17185 Date d'inscription dimanche 25 novembre 2007 Statut Membre Dernière intervention 15 avril 2024 - 4 août 2015 à 11:20
Bonjour,
je veux insérer des données via une interface VBA ,sous des conditions si OptionButton1= true and OptionButton3 il doit me faire l'ajout dans les colonnes B,C et D et ainsi de suite...
voila le code que j'ai utilisé mais malheureusement ça marche pas
Private Sub CommandButton1_Click()
Dim U As Integer
U = Sheets("Feuil5").Range("B" & Rows.Count).End(xlUp).Row + 1
If MsgBox("Etes vous sûr de vouloir ajouter ces informations?", vbYesNo, "Demande de confirmation") = vbYes Then
If OptionButton1 = True & OptionButton3 = True Then
Feuil5.Range("B" & U) = Val(TextBox1)
Feuil5.Range("C" & U).Value = ComboBox3
Feuil5.Range("D" & U).Value = ComboBox4
End If
If OptionButton1 = True & OptionButton4 = True Then
Feuil5.Range("E" & U) = Val(TextBox1)
Feuil5.Range("F" & U).Value = ComboBox3
Feuil5.Range("G" & U).Value = ComboBox4
End If
If OptionButton1 = True & OptionButton5 = True Then
Feuil5.Range("H" & U) = Val(TextBox1)
Feuil5.Range("I" & U).Value = ComboBox3
Feuil5.Range("J" & U).Value = ComboBox4
End If
If OptionButton2 = True & OptionButton3 = True Then
Feuil5.Range("L" & U) = Val(TextBox1)
Feuil5.Range("M" & U).Value = ComboBox3
Feuil5.Range("N" & U).Value = ComboBox4
End If
If OptionButton2 = True & OptionButton4 = True Then
Feuil5.Range("O" & U) = Val(TextBox1)
Feuil5.Range("P" & U).Value = ComboBox3
Feuil5.Range("Q" & U).Value = ComboBox4
End If
If OptionButton2 = True & OptionButton5 = True Then
Feuil5.Range("R" & U) = Val(TextBox1)
Feuil5.Range("S" & U).Value = ComboBox3
Feuil5.Range("T" & U).Value = ComboBox4
End If
End If
End Sub

1 réponse

f894009 Messages postés 17185 Date d'inscription dimanche 25 novembre 2007 Statut Membre Dernière intervention 15 avril 2024 1 701
4 août 2015 à 11:20
Bonjour,

comme ca ira mieux:

Private Sub CommandButton1_Click()
    Dim U As Integer
    U = Sheets("Feuil5").Range("B" & Rows.Count).End(xlUp).Row + 1
    If MsgBox("Etes vous sûr de vouloir ajouter ces informations?", vbYesNo, "Demande de confirmation") = vbYes Then
        If OptionButton1 = True Then
            If OptionButton3 = True Then
                Feuil5.Range("B" & U) = Val(TextBox1)
                Feuil5.Range("C" & U).Value = ComboBox3
                Feuil5.Range("D" & U).Value = ComboBox4
            ElseIf OptionButton4 = True Then
                Feuil5.Range("E" & U) = Val(TextBox1)
                Feuil5.Range("F" & U).Value = ComboBox3
                Feuil5.Range("G" & U).Value = ComboBox4
            ElseIf OptionButton5 = True Then
                Feuil5.Range("H" & U) = Val(TextBox1)
                Feuil5.Range("I" & U).Value = ComboBox3
                Feuil5.Range("J" & U).Value = ComboBox4
            End If
        End If
        If OptionButton2 = True Then
            If OptionButton3 = True Then
                Feuil5.Range("L" & U) = Val(TextBox1)
                Feuil5.Range("M" & U).Value = ComboBox3
                Feuil5.Range("N" & U).Value = ComboBox4
            ElseIf OptionButton4 = True Then
                Feuil5.Range("O" & U) = Val(TextBox1)
                Feuil5.Range("P" & U).Value = ComboBox3
                Feuil5.Range("Q" & U).Value = ComboBox4
            ElseIf OptionButton5 = True Then
                Feuil5.Range("R" & U) = Val(TextBox1)
                Feuil5.Range("S" & U).Value = ComboBox3
                Feuil5.Range("T" & U).Value = ComboBox4
            End If
       End If
    End If
End Sub


Pour Infos: si vous voulez faire un ET pour x test:

If OptionButton1 = True And OptionButton3 = True Then
0