Allow Grouping option on a Protected Worksheet/workbook

kgavin

New Member
Joined
Jul 8, 2010
Messages
8
Hello -

I have a workbook that I am password protecting so that users can only edit certain cells. I have areas that are grouped, however, and I when I protect the workbook, you cannot group/ungroup these columns. I found this thread and tried to incorporate it into my workbook:

http://www.mrexcel.com/forum/showthread.php?t=206683

I pasted this code into the "This Workbook" section of VBA:

Private Sub Workbook_Open()
Dim wksht As Worksheet
For Each wksht In ThisWorkbook.Sheets
With wksht
.Unprotect "tnskmg"
.EnableOutlining = True
.Protect "tnskmg", contents:=True, userInterfaceOnly:=True
End With
Next wksht
End Sub


Even after this, I still cannot group/ungroup columns when the book is protected.

Can someone help please? I would be more than happy to email an example of the file if that helps.

Thanks!
Kris
 
You need to include a For/Next loop outside your With statement to do that.
Code:
Private Sub Workbook_Open()
   For Each wks In ThisWorkbook.Worksheets(Array( _
   "US Custom", "NA Total", "Tru", "Foresight", "Canada", "NA Holdings"))
        With wks
            .Unprotect "tnskmg"
            .EnableOutlining = True
            .Protect "tnskmg", contents:=True, userInterfaceOnly:=True
        End With
    Next
End Sub


Thanks for putting this code out there. Really helped me out today.
 
Upvote 0

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Please advice what is the final conclusion. If I want the sheet to be protected and also allow user to group or ungroup column then what macro to use
 
Upvote 0
Hi Datsmart,

wow this is awesome! I have been looking for this piece of code all over the net for a while and this is the one one that works! Thank you very much!!

You need to include a For/Next loop outside your With statement to do that.
Code:
Private Sub Workbook_Open()
   For Each wks In ThisWorkbook.Worksheets(Array( _
   "US Custom", "NA Total", "Tru", "Foresight", "Canada", "NA Holdings"))
        With wks
            .Unprotect "tnskmg"
            .EnableOutlining = True
            .Protect "tnskmg", contents:=True, userInterfaceOnly:=True
        End With
    Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,477
Messages
6,125,037
Members
449,205
Latest member
Eggy66

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