Hello,
I am working on a macro that would delete all grouped rows (i.e. Grouped with menu:Data > Group and outline) in range print_area.
Below is what I came up with but unfortunately, it does not delete any grouped row...
Any help would be greatly appreciated.
Thanks and regards,
Louis
I am working on a macro that would delete all grouped rows (i.e. Grouped with menu:Data > Group and outline) in range print_area.
Below is what I came up with but unfortunately, it does not delete any grouped row...
Any help would be greatly appreciated.
Thanks and regards,
Louis
Code:
ub DeleteGroupedRows()
'For row deletion
Dim CalcSetting As Integer
Dim Sh As Worksheet
Dim TestRange As Range
Dim FirstRow As Long
Dim LastRow As Long
'Performance settings
CalcSetting = Application.Calculation
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
'Set TestRange
Set TestRange = ActiveSheet.Range("'" & ActiveSheet.Name & "'!" & "Print_Area")
If Not (TestRange Is Nothing) Then 'Range exist
'Set first and last rows
FirstRow = TestRange.Cells(1).Row
LastRow = TestRange.Cells(TestRange.Rows.Count).Row
'Loop through and delete non-relevant rows
For TestedRow = LastRow To FirstRow Step -1 'Backward loop required due to row deletion
If ActiveSheet.Rows(TestedRow).OutlineLevel > 0 Then
ActiveSheet.Rows(TestedRow).EntireRow.Delete
Else
End If
Next TestedRow
Else 'Range does not exist
Set TestRange = Nothing
End If
'Restore performance settings
Application.Calculation = CalcSetting
Application.ScreenUpdating = True
End Sub