VBA Supprimer un ligne de tableau suivant critère

Bonjour,

Je cherche à Supprimer la ligne de mon tableaux contenant ma ref obtenu par un Userform

Je ne peux pas faire EntierRow.Delate car j'ai d'autre tableau a côté.

Dim ref As String, lot As String,  LigP As Long, ResultatP As Long

On Error Resume Next

ref = ComboBox1.Value
lot = ComboBox5.Value

With Sheets("PRODUCTION")
    For LigP = 2 To .Range("B" & Rows.Count).End(xlUp).Row
        If .Range("B" & LigP) = ref And .Range("E" & LigP) = lot Then
             Resultat = LigP
             Exit For
        End If
    Next LigP
End With

1 er parti OK

Ici la parti ou j'ai un problème :

Idée 1:

'Sheets("PRODUCTION").listobjects("Tableau2").Range("B" & LigP).Select
'Selection.Range("B" & LigP).Delete

Ou 2 Idée :

'With Sheets("PRODUCTION").ListObjects("Tableau2")
'If .Range("B" & LigP) = ref Then
'.Range("B" & LigP).Row.Delete
'End If
'End With

Je vous remerci par avance de votre aide

Bonne journée

Cobzy

Bonjour Cobzy, le forum,

Vois si cet exemple peut t'aider.....

Private Sub CommandButton1_Click()
 Dim ref As String, lot As String, dl As Long, i As Long, compteur As Long
  ref = ComboBox1.Value
  lot = ComboBox2.Value
 If MsgBox("Etes-vous certain de vouloir supprimer ces lignes?", vbYesNo, "Demande de confirmation") = vbYes Then
  With Sheets("PRODUCTION")
   dl = .ListObjects("Tab_1").ListRows.Count
   compteur = 0
    For i = dl To 1 Step -1
     If .ListObjects("Tab_1").DataBodyRange(i, 2) = ref And .ListObjects("Tab_1").DataBodyRange(i, 5) = lot Then
      .ListObjects("Tab_1").ListRows(i).Delete
      compteur = compteur + 1
     End If
    Next i
  End With
 End If
 MsgBox compteur & " ligne(s) supprimée(s)": Unload Me
End Sub
11classeur1.xlsm (21.89 Ko)

Cordialement,

Merci xorsankukai

J'ai remanier pour que ca colle avec mon VBA, ça marche parfaitement !

J'ai enfin compris comment utiliser Databodyrange et listrows

Je les utilises jamais avec des variables...

Encore merci !

Bonne journée

Re,

J'ai remanier pour que ca colle avec mon VBA, ça marche parfaitement !

J'ai enfin compris comment utiliser Databodyrange et listrows

Super!

Merci d'avoir passé le sujet en résolu,

A bientôt,

Bonne soirée,

Rechercher des sujets similaires à "vba supprimer ligne tableau suivant critere"