PDA

View Full Version : Group and ungroup certain rows in a protected sheets



maytey
07-22-2009, 07:06 PM
Help!! How do i write a macro to group and ungroup rows in a protected sheet? The tricky thing is, i would like the users to ungroup/group certain rows within the protected sheets. In addition, my workbook has a few protected sheets. Hence, the codes i have researched could not help me at all...

Can someone pls help me?

Rdgs,
Helpless May

rbrhodes
07-22-2009, 07:53 PM
Hi May.

Protect with userintferaceonly = true ?

maytey
07-22-2009, 07:56 PM
Errmmm.. how should i write my codes?

mumin_abdul
07-23-2009, 02:05 PM
Group Rows (rows 2 through to 7):



Rows("2:7").Select
Selection.Rows.Group


Ungroup (row number 3)



Rows("3:3").Select
Selection.Rows.Ungroup

mumin_abdul
07-23-2009, 02:08 PM
Unprotect the sheet:



Sheets("Sheet1").Select
ActiveSheet.Unprotect

Protect the sheet:



Sheets("Sheet1").Select
ActiveSheet.Protect

maytey
07-27-2009, 04:12 AM
Hi dr,

how do you go about doing that? If you look at my attached file, i have many many groupings all over and i need to duplicate the files to different users. In addition, i have also a few sheets within the same workbook which have groupings and all the sheets are protected.

Can you help?

Thanks

Regards,
May




Hi May.

Protect with userintferaceonly = true ?

rbrhodes
07-27-2009, 01:19 PM
Hi May,

Put this code in the ThisWorkBook module.

<Alt +F11> to open the VB Editor.

There are 2 windows you will need to see: The Code window- has 2 dropdown boxes above it. One will say General and the other will say Decarations. The Project Explorer window: a list of Excel 'Objects'.

If you can see 'ThisWorkbook' in the Project Explorer window on the left, doubleclick on it. If you don't see the Project Explorer window use the View menu to open it, Click on the displayed objects '+' signs until you see ThisWorkbook, dbl click that.

Paste this code in the 'Code' window (on the right). The Boxes at the top will change to 'Workbook' and 'Open'. This is good.

Close the VBE, save and close the file. When you re-open you should have a fully protected set of sheets with Grouping enabled.




Option Explicit
Private Sub Workbook_Open()

Dim ws As Worksheet

For Each ws In ThisWorkbook.Worksheets
With ws
.Protect Password:="PASSWORD", userinterfaceonly:=True
.EnableOutlining = True
End With
Next ws

End Sub