Is it possible to lock all access to a particular sheet in a workbook?

Woblypegs

New Member
Joined
Apr 16, 2020
Messages
26
Office Version
  1. 365
Platform
  1. Windows
Hi folks, just wanting to know if it is possible to password lock a certain sheet in a book? By this I mean no-one can access the sheet without the password. I know you can password protect sheets where data can be protected but I need access to the sheet to be blocked unless you have the password.
We have a workbook that is shared and we want to add another sheet that uses the data from the existing sheets as well as has new data that we don't want the people this workbook is shared with to have access to.

Many Thanks
Wobly
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Maybe this
VBA Code:
Sub MM1()
Dim ws As Worksheet, ans As String
ans = InputBox("Enter your password")
  Select Case ans
    Case "password" 'change password to suit
        Sheets("Sheet1").Visible = xlVeryHidden
    Case "all" 'change password to suit
        For Each ws In Worksheets
                ws.Visible = True
        Next
    Case Else
        err = MsgBox("Incorrect Password", vbExclamation)
    End Select
End Sub
 
Upvote 0
Awesome Thanks very much. will have a play and see how it goes.
Wobly
 
Upvote 0
Hi again, I am fairly new to this excel stuff and have never used the VBA in excel. You may have to talk me through how I activate this code, I changed sheet1 to the sheet I wanted it to control (sheet3 in this case) and then entered the code in the vba editor first under the workbook and then under the sheet I want it to control to see which would work but nothing happened in either. What am I doing wrong?

Many Thanks
Wobly
 
Upvote 0
Ok, it can go in the "This Workbook" module.
Then to run it you go back to the workbook and either press ALT + F8 and then press run
OR
You can put a shape on the worksheet and r click the shape and select assign macro....then you just have to press the shape to activate the macro.....don't put the shape on sheet 3, of course
 
Upvote 0
Sorry for being a bit thick on this,but I've got the code working however, how do I set the password in the first place? it asks for the password but then just says incorrect password or subscript out of range.

Thanks
Wobly
 
Upvote 0
You don't need to password protect the sheet, simply put a password in this line
VBA Code:
ans = InputBox("Enter your password")
and then change the "password" in this line to the one you have inputted into the line above
VBA Code:
Case "password" 'change password to suit
 
Upvote 0
Hi Michael M, I did try that, Anyway this is what the code looks like.
SS14.png

but when I run it all I get is a message saying "Subscript out of range".
Wobly
 
Upvote 0
In that case you need to check your sheet name.
Check for extra spaces at each end...also make sure the "Sheet3" isn't "sheet 3" or "SHEET3"
 
Upvote 0

Forum statistics

Threads
1,215,433
Messages
6,124,861
Members
449,195
Latest member
MoonDancer

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