Petite macro

Soleil -  
pijaku Messages postés 13513 Date d'inscription   Statut Modérateur Dernière intervention   -
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

  1. pijaku Messages postés 13513 Date d'inscription   Statut Modérateur Dernière intervention   2 773
     
    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
    1. eriiic Messages postés 24581 Date d'inscription   Statut Contributeur Dernière intervention   7 281
       
      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
      0
    2. mic13710 Messages postés 1165 Date d'inscription   Statut Membre Dernière intervention   360
       
      salut eric,

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

      Michel
      0
    3. pijaku Messages postés 13513 Date d'inscription   Statut Modérateur Dernière intervention   2 773
       
      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...
      0