+ Reply to Thread
Results 1 to 10 of 10

Group/Ungroup in a Protected Sheet

Hybrid View

  1. #1
    Registered User
    Join Date
    06-21-2013
    Location
    US
    MS-Off Ver
    Excel 2010
    Posts
    7

    Group/Ungroup in a Protected Sheet

    All,

    I've been working on a budget template that has protected sheets with certain cells being made unprotected for the user to input data. Many of these unprotected cells have been grouped together for esthetic reasons.

    I'm trying to group and ungroup these data inputs while continuing to lock down the individual sheets.

    I've used the code below in the VB Editor under "THIS WORKSHEET" but am having no luck getting the groupings to be accessible when I protect the sheet with the same password.

    Any clue as to what I'm doing wrong?

    ....... [See Code Below] .......

    Private Sub Workbook_Open1()

    With Sheet7
    .Protect Password:="secret", UserInterfaceOnly:=Tru
    .EnableOutlining = True
    End With
    End Sub

    Private Sub Workbook_Open()
    With Sheet6
    .Protect Password:="secret", UserInterfaceOnly:=Tru
    .EnableOutlining = True
    End With
    End Sub

    Private Sub Workbook_Open2()
    With Sheet8
    .Protect Password:="secret", UserInterfaceOnly:=True
    .EnableOutlining = True
    End With
    End Sub

  2. #2
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Group/Ungroup in a Protected Sheet

    you can only have one workbook_open event-put all the protecting code in that
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  3. #3
    Registered User
    Join Date
    06-21-2013
    Location
    US
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Group/Ungroup in a Protected Sheet

    JosephP,

    Are you saying that it should be written like this....

    With Sheet7
    .Protect Password:="secret", UserInterfaceOnly:=Tru
    .EnableOutlining = True

    With Sheet6
    .Protect Password:="secret", UserInterfaceOnly:=Tru
    .EnableOutlining = True

    With Sheet8
    .Protect Password:="secret", UserInterfaceOnly:=True
    .EnableOutlining = True
    End With
    End Sub

  4. #4
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Group/Ungroup in a Protected Sheet

    almost ;-)
    With Sheet7
    .Protect Password:="secret", UserInterfaceOnly:=True
    .EnableOutlining = True
    End With
    With Sheet6
    .Protect Password:="secret", UserInterfaceOnly:=True
    .EnableOutlining = True
    End With
    With Sheet8
    .Protect Password:="secret", UserInterfaceOnly:=True
    .EnableOutlining = True
    End With
    End Sub
    or use a loop
       Dim ws
       For Each ws In Array(Sheet6, Sheet7, Sheet8)
          ws.Protect Password:="secret", userinterfaceonly:=True
          ws.EnableOutlining = True
       Next ws

  5. #5
    Registered User
    Join Date
    06-21-2013
    Location
    US
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Group/Ungroup in a Protected Sheet

    Now I've got a different problem.

    If I go into the VB Editor and go the amended code I have to press F8 and have the first line highlight yellow before the code will work.
    If I close the workbook and reopen the grouping/ungrouping doesn't work unless I first go to the VB Editor, go to the code and then press F8, back out and then it all works.

    Any reason this is happening?
    How can I make it so it works without the user having to step into the code and press F8?

    Thanks

  6. #6
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Group/Ungroup in a Protected Sheet

    what is the exact code you have in the ThisWorkbook module now?

  7. #7
    Registered User
    Join Date
    06-21-2013
    Location
    US
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Group/Ungroup in a Protected Sheet

    2014 Budget Template_Reforecast.xlsm

    I've attached the model

  8. #8
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Group/Ungroup in a Protected Sheet

    Private Sub Workbook_Open1()
    oughta be
    Private Sub Workbook_Open()

  9. #9
    Registered User
    Join Date
    06-21-2013
    Location
    US
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Group/Ungroup in a Protected Sheet

    That did it!
    Thanks for your help JosephP.

    Much appreciated.

  10. #10
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Group/Ungroup in a Protected Sheet

    you're welcome :-)

    don't forget to mark the thread solved, please

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1