Enable Group/Ungroup in protected sheet

Anonymous
2013-01-02T12:41:00+00:00

Dear solver,

 I have an excel sheet which is renamed as "Emp Summary" which is protected without password.

 In this protected sheet, I want to enable the Group/Ungroup option to show/hide row no. 34 to 42.

 How to do that? Will macro must be require? If yes, then please write the code for me. I would appreciate if this could be done withouth a macro, 

 even by other trick/option.

 Also, if I send the same file to another user, will he/she also requires to enable macro at his/her end?

 Please help.

 Many thanks.

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
Answer accepted by question author
HansV 462.7K Reputation points MVP Volunteer Moderator
2013-01-02T12:56:30+00:00

You need VBA for this, and the end user will need to allow macros for this to work.

Press Alt+F11 to activate the Visual Basic Editor.

Double-click ThisWorkbook, under Microsoft Excel Objects in the project explorer on the left hand side.

Copy the following code into the module that appears:

Private Sub Workbook_Open()

    With Worksheets("Emp Summary")

        .EnableOutlining = True

        .Protect UserInterfaceOnly:=True

    End With

End Sub

This code will be executed automatically each time the workbook is opened.

Was this answer helpful?

300+ people found this answer helpful.
0 comments No comments

91 additional answers

Sort by: Most helpful
  1. Anonymous
    2017-04-15T00:50:37+00:00

    You need VBA for this, and the end user will need to allow macros for this to work.

    Press Alt+F11 to activate the Visual Basic Editor.

    Double-click ThisWorkbook, under Microsoft Excel Objects in the project explorer on the left hand side.

    Copy the following code into the module that appears:

    Private Sub Workbook_Open()

        With Worksheets("Emp Summary")

            .EnableOutlining = True

            .Protect UserInterfaceOnly:=True

        End With

    End Sub

    This code will be executed automatically each time the workbook is opened.

    I am having the same issue and this code can't seem to work for me.  I have excel 2013 and in the worksheet I need to protect my formulas but allow users to expand / collapse columns. But as soon as I protect the sheet with a password, it freezes expand / collapsing feature or group / ungroup feature as well.  Any help would be highly appreciated.

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2017-04-14T05:34:09+00:00

    I have somewhat of a similar issue.

    I'm working on a Template that will be Themed but a few members on a monthly basis.

    All the Sheets are protected and the user is to basically just Background Fill the Cells, etc.

    All Sheets are to be Themed Identically.  But to avoid doing the same thing on each Sheet, they group the sheets first and then Them just the first sheet which in turn carries the same to the rest of the sheets.

    Unfortunately, Excel gives an error when changing the background with all sheets grouped even when all the

    [  ] checkboxes are selected upon protecting the sheets.

    Is there away to make theming of all the sheets at once while keeping them protected?

    I want to prevent the users from editing the text and the structure of the sheets/workbook but have full freedom to format the cells background/colors/ 

    My Sample Workbook

    Your help is really appreciated

    Thank you.

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2017-04-04T16:56:44+00:00

    Thanks, HansV

    So, in short, setting UserInterfaceOnly:=True allows me to make changes to a protected worksheet via macros that the user can't make directly.  This is exactly what I need.  I was worried because, the way the post I saw was worded, I got the impression that maybe setting that attribute might somehow make my code accessible to the user, but I see now that it is still secure, since it's password protected.

    Thanks again!

    HJ

    Was this answer helpful?

    0 comments No comments
  4. HansV 462.7K Reputation points MVP Volunteer Moderator
    2017-04-04T16:42:08+00:00

    You can protect a worksheet with UserInterfaceOnly:=True, as described higher up in this thread. If you do this, macros can perform many of the actions that users aren't allowed to perform in a protected sheet.

    For example, the user can only edit unlocked cells on a protected worksheet. For example, if A1 is locked, trying to edit A1 will result in an error message:

    If the sheet has been protected the normal way, the line of code

    Range("A1").Value = 37

    would cause an error message too. But if the sheet has been protected with UserInterfaceOnly:=True, the value of A1 will be set without error.

    Was this answer helpful?

    0 comments No comments