F freshtomm Member Mar 17, 2017 #1 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: Mar 17, 2017
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.
PCosta87 Well-Known Member Mar 17, 2017 #2 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.
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.