How to Select Multiple Sheets in Excel

jwindholz2725

Board Regular
Joined
Sep 20, 2011
Messages
94
Can anyone please help? I currently have a code to protect all sheets at once with a password. (see below) The issue is this workbook gets passed around and people add new sheets. Thus when I lock workbook their sheets are locked as well. How can I lock say sheets "<" through ">"? On my template my sheets will always be between < and > and their sheets will remain outside the range.

Sub ProtectAllSheets()
Application.ScreenUpdating = False
Dim N As Long
For N = 1 To Sheets.Count
Sheets(N).Protect _
Password:="locked", _
DrawingObjects:=False, _
Contents:=True, _
Scenarios:=False, _
AllowFormattingCells:=True, _
AllowFormattingColumns:=True, _
AllowFormattingRows:=True, _
AllowInsertingColumns:=False, _
AllowInsertingRows:=False, _
AllowInsertingHyperlinks:=False, _
AllowDeletingColumns:=False, _
AllowDeletingRows:=False, _
AllowSorting:=False, _
AllowFiltering:=False, _
AllowUsingPivotTables:=False
Next N
Application.ScreenUpdating = True
End Sub
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Thanks that works but the issue is I can add potentially a 100 sheets to my work book. So the number ranges would always change. So I need a something that protects say tab "<" to tab ">" specifically. That way anything I put in the middle of that will always get proctected.
 
Upvote 0
Try

Code:
For i = 1 To Sheets.Count
    If Sheets(i).Name = "<" Then
        first = i
        Exit For
    End If
Next i
For i = 1 To Sheets.Count
    If Sheets(i).Name = ">" Then
        last = i
        Exit For
    End If
Next i
For N = first To last
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,289
Members
452,902
Latest member
Knuddeluff

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