ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Protecting and Unprotecting more than 1 worksheets (https://www.excelbanter.com/excel-programming/413673-protecting-unprotecting-more-than-1-worksheets.html)

Jeffrey[_2_]

Protecting and Unprotecting more than 1 worksheets
 
Hi all. Is it possible to protect and unprotect more than 1
worksheets. Say the first 4 worksheet in a workbook using VBA codes?
Thanks much.

Jeff

Gord Dibben

Protecting and Unprotecting more than 1 worksheets
 
Sub Protect_Some_Sheets()
Application.ScreenUpdating = False
Dim N As Single
For N = 1 To 4
'for all sheets use N = 1 to Sheets.Count
Sheets(N).Protect Password:="justme"
Next N
Application.ScreenUpdating = True
End Sub


Gord Dibben MS Excel MVP



On Mon, 7 Jul 2008 14:36:55 -0700 (PDT), Jeffrey wrote:

Hi all. Is it possible to protect and unprotect more than 1
worksheets. Say the first 4 worksheet in a workbook using VBA codes?
Thanks much.

Jeff



Gord Dibben

Protecting and Unprotecting more than 1 worksheets
 
Or this for selected sheets.

Sub Protect_Selected_Sheets()
Set MySheets = ActiveWindow.SelectedSheets
For Each ws In MySheets
ws.Select
ws.Protect Password:="justme"
Next ws
End Sub


Gord

On Mon, 07 Jul 2008 14:52:13 -0700, Gord Dibben <gorddibbATshawDOTca wrote:

Sub Protect_Some_Sheets()
Application.ScreenUpdating = False
Dim N As Single
For N = 1 To 4
'for all sheets use N = 1 to Sheets.Count
Sheets(N).Protect Password:="justme"
Next N
Application.ScreenUpdating = True
End Sub


Gord Dibben MS Excel MVP



On Mon, 7 Jul 2008 14:36:55 -0700 (PDT), Jeffrey wrote:

Hi all. Is it possible to protect and unprotect more than 1
worksheets. Say the first 4 worksheet in a workbook using VBA codes?
Thanks much.

Jeff



Matthew Norman

Protecting and Unprotecting more than 1 worksheets
 
On Jul 8, 1:36*am, Jeffrey wrote:
Hi all. Is it possible to protect and unprotect more than 1
worksheets. Say the first 4 worksheet in a workbook using VBA codes?
Thanks much.

Jeff


it is very simple. loop through the sheets protecting each one in turn

Eg:

Sub Doit()
i = 1
Do Until i = 4
Sheets(i).Activate
ActiveSheet.Protect

i = i + 1
Loop

End Sub



End Sub

Jeffrey[_2_]

Protecting and Unprotecting more than 1 worksheets
 
On Jul 8, 9:53*am, Gord Dibben <gorddibbATshawDOTca wrote:
Or this for selected sheets.

Sub Protect_Selected_Sheets()
Set MySheets = ActiveWindow.SelectedSheets
For Each ws In MySheets
*ws.Select
* *ws.Protect Password:="justme"
Next ws
End Sub

Gord



On Mon, 07 Jul 2008 14:52:13 -0700, Gord Dibben <gorddibbATshawDOTca wrote:
Sub Protect_Some_Sheets()
* *Application.ScreenUpdating = False
* *Dim N As Single
* *For N = 1 To 4
'for all sheets use *N = 1 to Sheets.Count
* * * *Sheets(N).Protect Password:="justme"
* *Next N
* *Application.ScreenUpdating = True
End Sub


Gord Dibben *MS Excel MVP


On Mon, 7 Jul 2008 14:36:55 -0700 (PDT), Jeffrey wrote:


Hi all. Is it possible to protect and unprotect more than 1
worksheets. Say the first 4 worksheet in a workbook using VBA codes?
Thanks much.


Jeff- Hide quoted text -


- Show quoted text -


Hi Gord,

Thanks much. This works very well.

Cheers.

Jeff


All times are GMT +1. The time now is 03:24 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com