Delete all grouped rows

lovallee

Board Regular
Joined
Jul 8, 2002
Messages
219
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

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
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.

Forum statistics

Threads
1,202,905
Messages
6,052,481
Members
444,586
Latest member
Godtymer

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top