Supprimer ligne via userform

Bonjour le forum,

Alor voila j'ai une macro qui me permet de supprimer une ligne en fonction de la valeur d'une combobox:

Dim tx As String
    If TextBox1L = "" Then Exit Sub
    tx = TextBox1.Value

    Do
        Set rng = Sheets("aaa").Range("B:B").Find(tx)

        If rng Is Nothing Then
            Exit Do
        Else
        Sheets("aaa").Rows(rng.Row).Delete

        End If
    Loop

Cependant j'aimerais étoffer la macro en rajoutant une valeur: que la ligne soit supprimer que si elle contient à la fois textbox1 et textbox2.

J'espère être clair.

Merci d'avance.

bonjour,

suivant comment est constitué le Userform , on a peut-être déjà le N° de ligne à supprimer (listindex d'une combobox .....)

sinon à partir du code fourni une possibilité:

If rng Is Nothing Then
            Exit Do
 Else
       If  Sheets("aaa").cells(rng.row,10).value= textbox2.value then ' 10 pour le N° colonne à adapter
             Sheets("aaa").Rows(rng.Row).Delete
       End If

End If

A+

Bonsoir,

exemple de code ci-dessous :

    Dim cell As Range, cell1 As Range, cell2 As Range, lignes_à_supprimer As Range

    If textbox1 = "" Or textbox2 = "" Then Exit Sub

    With Sheets("aaa")
        Set cell = .Range("B:B").Find(textbox1)
        If Not cell Is Nothing Then
            Set cell1 = cell
            Do
                Set cell2 = cell.EntireRow.Find(textbox2)
                If Not cell2 Is Nothing Then
                    If lignes_à_supprimer Is Nothing Then Set lignes_à_supprimer = cell.EntireRow _
                    Else Set lignes_à_supprimer = Union(lignes_à_supprimer, cell.EntireRow)
                End If
                Set cell = .Range("B:B").Find(textbox1, after:=cell)
            Loop Until cell.Address = cell1.Address
        End If
    End With
    lignes_à_supprimer.Delete

Bonjour thev merci pour le code.

Mais un message erreur apparaît: erreur de compilation / boucle sans do...

Mais un message erreur apparaît: erreur de compilation / boucle sans do..

Communiquez le code complet de votre procédure Sub.

Voilà:

Private Sub SUPPRIMER_Click()

  Dim Rep

  Rep = MsgBox("!!!Vous êtes sur le point de supprimer une tenue de la réserve!!!" & Chr(10) & Chr(10) & "Poursuivre ?", vbYesNo)
   If Rep = vbNo Then
     Exit Sub
  Else
End If

Dim cell As Range, cell1 As Range, cell2 As Range, lignes_à_supprimer As Range
        If ComboboxEFFET = " " Or TextBoxNUMERO = " " Then Exit Sub

        With Sheets("TDF RESERVE")
            Set cell = .Range("C:C").Find(ComboboxEFFET)
            If Not cell Is nothinf Then
                Set cell1 = cell

                    Do

                    Set cell2 = cell.EntireRow.Find(TextBoxNUMERO)
                        If Not cell2 Is Nothing Then
                            If lignes_à_supprimer Is Nothing Then
                                Set lignes_à_supprimer = cell.EntireRow

                    Else: Set lignes_à_supprimer = Union(lignes_à_supprimer, cell.EntireRow)
                    End If

                    Set cell = Range("B:B").Find(ComboboxEFFET, after:=cell)

                    Loop Until cell.address

                    End If

                End With

                ligne_à_supprimer.Delete

          Unload Me

MAJ_TDF_RESERVE.Hide

End Sub

ceci devrait être mieux

Private Sub SUPPRIMER_Click()

    Dim Rep As Integer
    Dim cell As Range, cell1 As Range, cell2 As Range, lignes_à_supprimer As Range

    Rep = MsgBox("!!!Vous ?tes sur le point de supprimer une tenue de la réserve!!!" & Chr(10) & Chr(10) & "Poursuivre ?", vbYesNo)
    If Rep = vbNo Then Exit Sub

    If ComboboxEFFET = Empty Or TextBoxNUMERO = Empty Then Exit Sub

    With Sheets("TDF RESERVE")
        Set cell = .Range("C:C").Find(ComboboxEFFET)
        If Not cell Is Nothing Then
            Set cell1 = cell
            Do
                Set cell2 = cell.EntireRow.Find(TextBoxNUMERO)
                If Not cell2 Is Nothing Then
                    If lignes_à_supprimer Is Nothing Then Set lignes_à_supprimer = cell.EntireRow _
                    Else Set lignes_à_supprimer = Union(lignes_à_supprimer, cell.EntireRow)
                End If
                Set cell = .Range("C:C").Find(ComboboxEFFET, after:=cell)

            Loop Until cell.Address = cell1.Address
        End If
    End With

    ligne_à_supprimer.Delete

    Unload Me

    MAJ_TDF_RESERVE.Hide

End Sub
Rechercher des sujets similaires à "supprimer ligne via userform"