If OUTLINE exists remove it in VBA

  • Thread starter Thread starter QB
  • Start date Start date

QB

Board Regular
Joined
Jul 5, 2004
Messages
93
Hi

I want to check whether there is a worksheet has an outline in VBA. If there is I want to use Cells.ClearOutline to clear the old oytline and then add a new outline.

Can anyone help?

Thanks

Q
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Hi

Thanks for your code but it does not exclude any code to celar any EXISTING outlines below adding new groups.

Any other ideas?

Regards
 
Upvote 0
Adding the removal code you posted at the beginning of the other sample code will clear any old outlining.
Code:
Sub AutoGroup()
    'Remove any Outlining on worksheet
    Cells.ClearOutline
    'Begin new Outlining
    Range("B2").Select
    Do Until ActiveCell = "" And ActiveCell.Offset(1, 0) = ""
        If ActiveCell.Offset(0, -1) <> "" Then
            SR = ActiveCell.Offset(1, 0).Row
            Do Until ActiveCell <> "" And ActiveCell.Offset(1, -1) <> ""
                ActiveCell.Offset(1, 0).Activate
                If ActiveCell = "" And ActiveCell.Offset(1, 0) = "" Then GoTo LastGroup
            Loop
            ER = ActiveCell.Row
        End If
        Rows(SR & ":" & ER).Group
        ActiveSheet.Outline.SummaryRow = xlAbove
        ActiveCell.Offset(1, 0).Activate
        If ActiveCell = "" And ActiveCell.Offset(1, 0) = "" Then Exit Sub
    Loop
LastGroup:
    ER = ActiveCell.Offset(-1, 0).Row
    Rows(SR & ":" & ER).Group
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,587
Messages
6,179,733
Members
452,939
Latest member
WCrawford

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