Intégrer les informations d'une Listbox en fonction d'une CheckBox

Bonjour à tous,

J'ai le code suivant:

Private Sub CommandButton1_Click()
If IsNull(ListBox1.Value) = True Then
MsgBox "Veuillez selectionner une cloison dans la liste"
Exit Sub
End If
If TextBox2.Value = "" And IsNull(ListBox1.Value) = False Then
MsgBox "Veuillez renseigner le champs 'Qté ou m²' "
Else
If CheckBox12.Value = False Then
Dim ligne As Integer
If MsgBox("Confirmez-vous l'ajout des données?", vbYesNo, "confirmation") = vbYes Then
Worksheets("Estimation").Select
ligne = Sheets("Estimation").Range("C41").End(xlUp).Row + 1
With ListBox1
Cells(ligne, 1) = .List(.ListIndex, 0)
Cells(ligne, 3) = .List(.ListIndex, 1)
Cells(ligne, 4) = .List(.ListIndex, 2)
Cells(ligne, 5) = .List(.ListIndex, 3)
Cells(ligne, 6) = .List(.ListIndex, 4)
Cells(ligne, 7) = .List(.ListIndex, 6)
Cells(ligne, 8) = TextBox2.Value
Cells(ligne, 15) = .List(.ListIndex, 7)
End With
End If
With TextBox2
TextBox2.Value = ""
End With
End If
End If
End Sub

Celui-ci consiste à intégrer les informations d"une ListeBox1 dans la cellule vide au dessus de "C41" dans la feuille,si la CheckBox12 n'est pas coché.

Par contre, j'aimerais que ces même informations aillent dans la cellule vide au dessus de "C57" si la CheckBox12 est cochée.

Merci d'avance

Bonjour,

A tester :

Private Sub CommandButton1_Click()
Dim ligne As Integer
If IsNull(ListBox1.Value) = True Then
    MsgBox "Veuillez selectionner une cloison dans la liste"
    Exit Sub
End If
If TextBox2.Value = "" And IsNull(ListBox1.Value) = False Then
    MsgBox "Veuillez renseigner le champs 'Qté ou m²' "
Else
    If CheckBox12.Value = False Then
        ligne = Sheets("Estimation").Range("C41").End(xlUp).Row + 1
    Else
        ligne = Sheets("Estimation").Range("C57").End(xlUp).Row + 1 '   ajout ICI
    End If
    If MsgBox("Confirmez-vous l'ajout des données?", vbYesNo, "confirmation") = vbYes Then
        Worksheets("Estimation").Select
        With ListBox1
            Cells(ligne, 1) = .List(.ListIndex, 0)
            Cells(ligne, 3) = .List(.ListIndex, 1)
            Cells(ligne, 4) = .List(.ListIndex, 2)
            Cells(ligne, 5) = .List(.ListIndex, 3)
            Cells(ligne, 6) = .List(.ListIndex, 4)
            Cells(ligne, 7) = .List(.ListIndex, 6)
            Cells(ligne, 8) = TextBox2.Value
            Cells(ligne, 15) = .List(.ListIndex, 7)
        End With
        With TextBox2
            .Value = ""
        End With
    End If
End If
End Sub

Merci Pijaku.

La solution marche du feu de dieu !!!!

Bonjour,

Petite modif qui évite de sélectionner la feuille Estimation :

Private Sub CommandButton1_Click()
Dim ligne As Integer
If IsNull(ListBox1.Value) = True Then
    MsgBox "Veuillez selectionner une cloison dans la liste"
    Exit Sub
End If
If TextBox2.Value = "" And IsNull(ListBox1.Value) = False Then
    MsgBox "Veuillez renseigner le champs 'Qté ou m²' "
Else
    If CheckBox12.Value = False Then
        ligne = Sheets("Estimation").Range("C41").End(xlUp).Row + 1
    Else
        ligne = Sheets("Estimation").Range("C57").End(xlUp).Row + 1 '   ajout ICI
    End If
    If MsgBox("Confirmez-vous l'ajout des données?", vbYesNo, "confirmation") = vbYes Then
        With ListBox1
            Worksheets("Estimation").Cells(ligne, 1) = .List(.ListIndex, 0)
            Worksheets("Estimation").Cells(ligne, 3) = .List(.ListIndex, 1)
            Worksheets("Estimation").Cells(ligne, 4) = .List(.ListIndex, 2)
            Worksheets("Estimation").Cells(ligne, 5) = .List(.ListIndex, 3)
            Worksheets("Estimation").Cells(ligne, 6) = .List(.ListIndex, 4)
            Worksheets("Estimation").Cells(ligne, 7) = .List(.ListIndex, 6)
            Worksheets("Estimation").Cells(ligne, 8) = TextBox2.Value
            Worksheets("Estimation").Cells(ligne, 15) = .List(.ListIndex, 7)
        End With
        With TextBox2
            .Value = ""
        End With
    End If
End If
End Sub

Merci beaucoup, Franck

Rechercher des sujets similaires à "integrer informations listbox fonction checkbox"