Simplifier code suppression

Bonjour tout le monde, je cherche une solution pour simplifier ce code de suppression de données.

Suppression des données de la feuille CAISSE colonne E à J

Suppression des données de la feuille JOURNAL colonne A à AP

Merci

33suppression.xlsm (0.97 Mo)

Private Sub CommandButton5_Click()

Dim rep As Integer

rep = MsgBox("Voulez-vous supprimer l'opération du " & TextBox1, vbQuestion + vbYesNo)

If rep = vbYes Then

Sheets("CAISSE").Cells(ComboBox1.ListIndex + 4, 5).Delete Shift:=xlUp

Sheets("CAISSE").Cells(ComboBox1.ListIndex + 4, 6).Delete Shift:=xlUp

Sheets("CAISSE").Cells(ComboBox1.ListIndex + 4, 7).Delete Shift:=xlUp

Sheets("CAISSE").Cells(ComboBox1.ListIndex + 4, 8).Delete Shift:=xlUp

Sheets("CAISSE").Cells(ComboBox1.ListIndex + 4, 9).Delete Shift:=xlUp

Sheets("CAISSE").Cells(ComboBox1.ListIndex + 4, 10).Delete Shift:=xlUp

Sheets("JOURNAL").Cells(ComboBox1.ListIndex + 3, 1).Delete Shift:=xlUp

Sheets("JOURNAL").Cells(ComboBox1.ListIndex + 3, 2).Delete Shift:=xlUp

Sheets("JOURNAL").Cells(ComboBox1.ListIndex + 3, 3).Delete Shift:=xlUp

Sheets("JOURNAL").Cells(ComboBox1.ListIndex + 3, 4).Delete Shift:=xlUp

Sheets("JOURNAL").Cells(ComboBox1.ListIndex + 3, 5).Delete Shift:=xlUp

Sheets("JOURNAL").Cells(ComboBox1.ListIndex + 3, 6).Delete Shift:=xlUp

Sheets("JOURNAL").Cells(ComboBox1.ListIndex + 3, 7).Delete Shift:=xlUp

Sheets("JOURNAL").Cells(ComboBox1.ListIndex + 3, 8).Delete Shift:=xlUp

Sheets("JOURNAL").Cells(ComboBox1.ListIndex + 3, 9).Delete Shift:=xlUp

Sheets("JOURNAL").Cells(ComboBox1.ListIndex + 3, 10).Delete Shift:=xlUp

Sheets("JOURNAL").Cells(ComboBox1.ListIndex + 3, 11).Delete Shift:=xlUp

Sheets("JOURNAL").Cells(ComboBox1.ListIndex + 3, 12).Delete Shift:=xlUp

Sheets("JOURNAL").Cells(ComboBox1.ListIndex + 3, 13).Delete Shift:=xlUp

Sheets("JOURNAL").Cells(ComboBox1.ListIndex + 3, 14).Delete Shift:=xlUp

Sheets("JOURNAL").Cells(ComboBox1.ListIndex + 3, 15).Delete Shift:=xlUp

Sheets("JOURNAL").Cells(ComboBox1.ListIndex + 3, 16).Delete Shift:=xlUp

Sheets("JOURNAL").Cells(ComboBox1.ListIndex + 3, 17).Delete Shift:=xlUp

Sheets("JOURNAL").Cells(ComboBox1.ListIndex + 3, 18).Delete Shift:=xlUp

Sheets("JOURNAL").Cells(ComboBox1.ListIndex + 3, 19).Delete Shift:=xlUp

Sheets("JOURNAL").Cells(ComboBox1.ListIndex + 3, 20).Delete Shift:=xlUp

Sheets("JOURNAL").Cells(ComboBox1.ListIndex + 3, 21).Delete Shift:=xlUp

Sheets("JOURNAL").Cells(ComboBox1.ListIndex + 3, 22).Delete Shift:=xlUp

Sheets("JOURNAL").Cells(ComboBox1.ListIndex + 3, 41).Delete Shift:=xlUp

Sheets("JOURNAL").Cells(ComboBox1.ListIndex + 3, 42).Delete Shift:=xlUp

End If

End Sub

Bonjour,

Pour le principe.

A tester.

Cdlt.

Private Sub CommandButton5_Click()
Dim rep As VbMsgBoxResult, n As Long
    rep = MsgBox("Voulez-vous supprimer l'opération du " & TextBox1, vbQuestion + vbYesNo)
    If rep = vbYes Then
        n = Me.ComboBox1.ListIndex
        Set Ws = ActiveWorkbook.Worksheets("CAISSE")
        With Ws
            .Cells(n + 4, 5).Resize(, 6).Delete Shift:=xlUp
        End With
        Set Ws = ActiveWorkbook.Worksheets("JOURNAL")
        With Ws
            .Cells(n + 3, 1).Resize(, 15).Delete Shift:=xlUp
        End With
    End If
End Sub

Bonjour, utilise ce type de code :

Sheets("Caisse").Columns("E:J").Delete Shift:=xlToLeft
Sheets("Journal").Columns("A:AP").Delete Shift:=xlToLeft

Au plus simple

EDIT

Dsl j'avais pas ouvert ton fichier. Du coup le code n'est pas adapté à la situation :/

Merci pour vos réponses, je restes celà après le travail, ce soir

Bonjour,

je te retourne ton fichier Excel :

17suppression.xlsm (127.32 Ko)

sur la feuille "CAISSE", fais Ctrl e


Alt F11 pour voir le code VBA, puis revenir sur Excel

j'ai fait plein d'modifs, alors regarde partout !

si besoin, tu peux demander une adaptation.

merci de me dire si ça te convient.

dhany

Merci, je regarde ce soir

Merci dhany et Jean-Eric , vos 2 solutions fonctionnent parfaitement

Bon weekend

Citaro

merci pour ton retour ! pour passer le sujet en résolu, clique sur à droite de (coin haut droit du post)

ça permet aussi de clôturer le fil de la discussion (toi seul peut le faire, car c'est toi qui a créé ce sujet).

bon weekend à toi aussi.

dhany

Rechercher des sujets similaires à "simplifier code suppression"