Grouper des lignes en VBA

Bonjour,

je vous sollicite car je n'arrive pas à "grouper" des lignes en VBA en fonction de certaines cellules.

"Je souhaite en VBA sur Sheet2, grouper les lignes qui n'ont pas de valeurs en colonne D de la première ligne à la derniere ligne colonne C.

(voir fichier joint sheet Resultat)"

Merci de votre aide !

Bonne journée

303group-vba.xlsx (12.59 Ko)

bonjour le forum,

voici une macro qui fonctionne chez moi avec ton fichier, à adapter si besoin.

Sub Macro1()

For Each Cel In Range("D2:D" & Range("D" & Rows.Count).End(xlUp).Row)
    r = Cel.Row
        If Cel.Value = "" Then
            derlig = Columns(4).Find("*", Cel, , xlByRows, xlNext).Row - 1
            Range("D" & r & ":D" & derlig).Rows.Group
        End If
Next Cel

End Sub

A plus !

Merci !

J'ai ajouté une petite ligne pour faire un "collapse".

For Each Cel In Range("D2:D" & Range("D" & Rows.Count).End(xlUp).Row)

r = Cel.Row

If Cel.Value = "" Then

derlig = Columns(4).Find("*", Cel, , xlByRows, xlNext).Row - 1

Range("D" & r & ":D" & derlig).Rows.Group

End If

Next Cel

ActiveSheet.Outline.ShowLevels RowLevels:=1 ' to collapse the rows

Bonne journée

Rechercher des sujets similaires à "grouper lignes vba"