Petite macro

Bonjour à tous,

Voilà mon petit souci sur la feuil1 j'ai en ligne L7 à L5000 des chiffres qui peuvent se répéter...

8
8
8
15
15
850
850

Est-ce possible de créer une macro qui intercale un ligne blanche à chaque fois que le chiffre est différent.

8
8
8

15
15

850
850

Ca devrait donner ça... Merci à tous pour votre aide.

1 réponse

  • Votes
  • Date
  • Date décroissante
  1. Modérateur
    Bonjour, Une petite macro :
    Sub essai()
    Dim Lig As Integer, col As Integer
    col = 1 'à adapter, ici le test est fait sur la colonne 1 : A
    For Lig = 8 To Cells(65536, col).End(xlUp).Row
        If Cells(Lig, col) <> Cells(Lig - 1, col) And Cells(Lig - 1, col) <> "" Then
            Rows(Lig).Insert Shift:=xlDown
        End If
    Next
    End Sub
    1. Contributeur
      Salut pijaku,

      Tu devrais faire ta boucle à l'envers car l'insertion de ligne change la fin (qui reste fixe) :

      For Lig = Cells(65536, col).End(xlUp).Row to 8 step -1
      Necessite peut-être une adaptation des tests (?)

      eric
    2. salut eric,

      Vous devriez savoir ça : comment se comporte ce code avec les versions 2007 ou 2010 ?
      D'avance merci.

      Michel
    3. Modérateur
      Oups!!! Soirée arrosée hier... Pas réveillé, j'vais chercher du café!
      Dim Lig As Integer, col As Integer, DerLig As Integer
      col = 1 'à adapter, ici le test est fait sur la colonne 1 : A
      DerLig = Cells(65536, col).End(xlUp).Row - 1
      For Lig = DerLig To 2 Step -1
          If Cells(Lig, col) <> Cells(Lig + 1, col) And Cells(Lig + 1, col) <> "" Then
              Rows(Lig + 1).Insert Shift:=xlDown
          End If
      Next

      Salut Eriiic et merci du coup de main...