• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Group/ungroup selection in one macro

freshtomm

Member
Hello,

i need VBA to recognise wether selection is grouped and in that case ungroup it, or recognise wheter selection is ungrouped and in that case group it. In one VBA code. With group i mean Data>Group/Ungroup function. Is that possible?

Thanks.
 
Last edited:
Hi,

You can use the "OutlineLevel" property... >1 means it is grouped!

This should do it for the first 10 rows:
Code:
Sub Group_Ungroup()

    Dim i As Integer
   
    For i = 1 To 10
        If Rows(i).OutlineLevel > 1 Then
            Rows(i).Ungroup
        Else
            Rows(i).Group
        End If
    Next i

End Sub

Change as necessary.

Hope this helps.
 
Back
Top