How to Expand or Collapse Row Groups on a Protected Excel Worksheet
Question details
The user needs to be able to expand or collapse outline row or column groups while an Excel worksheet is password-protected.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- The user has grouped rows or columns to organize data in an Excel worksheet and then protected the sheet to prevent unauthorized editing or formatting changes.
- Observed behavior
- After protecting the worksheet, the '+' and '-' outline buttons become unresponsive or unavailable. Selecting 'Format rows' and 'Format columns' in the protection dialog box does not restore outline functionality.
Ensure you have the password used to protect the worksheet, as you will need to unprotect it temporarily. If you plan to use the macro solution, save a backup copy of your workbook first.
Use a VBA Macro to Preserve Outline Functionality
Since Excel's default protection dialog does not allow outline expansion, using a simple VBA script allows the worksheet to remain protected while keeping outline controls fully active for users.
This method uses the 'UserInterfaceOnly' parameter in VBA, which applies protection only to the user interface while allowing macros to manipulate the sheet. Combined with the 'EnableOutlining' property, this solves the grouping restriction.
Press Alt + F11 on your keyboard to open the Visual Basic for Applications (VBA) Editor in Excel.
In the Project Explorer pane on the left, find your workbook name and double-click on 'ThisWorkbook' to open its code window.
Paste the following code: Private Sub Workbook_Open() With Worksheets("Sheet1") .Protect Password:="yourpassword", UserInterfaceOnly:=True .EnableOutlining = True End With End Sub. Be sure to replace 'Sheet1' and 'yourpassword' with your actual sheet name and password.
Close the VBA Editor. Go to File > Save As, and change the file format to 'Excel Macro-Enabled Workbook (*.xlsm)'. Close and reopen the file for the code to take effect.

Temporarily Unprotect the Worksheet to Adjust Groups
If you do not want to use VBA macros, the simplest manual workaround is to temporarily remove the sheet's protection, expand or collapse your groups, and reapply the protection.
Easily Manage Protected Sheets with WPS Spreadsheet
WPS Spreadsheet offers robust worksheet protection and grouping tools. You can easily manage data outlines, protect sensitive information, and utilize macros in WPS Office without subscription fees.
- 1. Group Rows or Columns: Open your workbook in WPS Spreadsheet. Select the rows or columns you want to group, go to the 'Data' tab, and click 'Group'.
- 2. Protect the Worksheet: To protect the sheet, navigate to the 'Review' tab and select 'Protect Sheet'. Choose the permissions you want to grant to users.
- 3. Utilize WPS Macros: For advanced controls like expanding groups on a protected sheet, access the 'Developer' tab in WPS Spreadsheet to run identical VBA scripts.

Frequently Asked Questions
Why does checking 'Format rows' and 'Format columns' not allow grouping on a protected sheet?
Excel treats grouping and outlining as structural changes rather than standard cell formatting. Because there is no specific checkbox for 'Allow Outlining' in the default Protect Sheet dialog, checking formatting options does not bypass the structural restriction.
Can I apply the VBA outlining fix to multiple protected sheets at once?
Yes. In the VBA 'Workbook_Open' event, you can use a loop (e.g., 'For Each ws In ThisWorkbook.Worksheets') to apply the '.EnableOutlining = True' and '.Protect' methods to all sheets in the workbook automatically upon opening.
Will the VBA macro solution work if I share the file with colleagues?
Yes, as long as your colleagues open the file in a desktop version of Excel that supports macros and they choose to 'Enable Content' when prompted. Note that VBA macros will not function in Excel for the Web.




