Suprimer ligne

Bonjour,

Quelqu’un pourrais m'aider a simplifier ce code pour faire une boucle jusqu’à la colonne K par exemple?

Cordialement,

Bob

Sub netoyer()

  Dim dlig&: Application.ScreenUpdating = 0
  dlig = Cells(Rows.Count, 1).End(xlUp).Row
  If dlig > 1 Then Range("A2:A" & dlig).ClearContents
  dlig = Cells(Rows.Count, 2).End(xlUp).Row
  If dlig > 1 Then Range("B2:B" & dlig).ClearContents
  dlig = Cells(Rows.Count, 3).End(xlUp).Row
  If dlig > 1 Then Range("C2:C" & dlig).ClearContents
  dlig = Cells(Rows.Count, 4).End(xlUp).Row
  If dlig > 1 Then Range("D2:D" & dlig).ClearContents
  dlig = Cells(Rows.Count, 5).End(xlUp).Row
  If dlig > 1 Then Range("E2:E" & dlig).ClearContents

End Sub

Bonjour,

Un essai ...

Sub netoyer()
Dim dlig&
Dim C&
   Application.ScreenUpdating = 0

   For C = 1 To 11
      dlig = Cells(Rows.Count, C).End(xlUp).Row
      If dlig > 1 Then Range(Cells(2, C), Cells(dlig, C)).ClearContents
   Next C
End Sub

ric

Merci, c'est parfait.

Cordialement,

Bob

ric

Bonjour,

J'ai repensé à ta demande, ceci serait plus simple :

Sub netoyer()
Dim dlig&
   Application.ScreenUpdating = 0
   dlig = ActiveSheet.UsedRange.Rows.Count
   Range("A2:K" & dlig).ClearContents
End Sub

ric

Bonjour,

Oui en effet je trouve ce code mieux.

Merci.

Bob

Rebonjour,

On pourrait même simplifier ainsi :

Sub netoyer()
   Application.ScreenUpdating = 0
   Range("A2:K" & ActiveSheet.UsedRange.Rows.Count).ClearContents
End Sub

ric

rebonjour,

Simplification optimum la je pense

Merci,

Bob

Rechercher des sujets similaires à "suprimer ligne"