Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How can I set password for a sheet in excel

Posted on 2016-10-28
4
Medium Priority
?
119 Views
Last Modified: 2016-10-28
Hello experts,

I need to give password to one of the sheets in my excel file. I have two excel sheets in my workbook (Input, and Report).

I want to give password to "Report" sheet.

thanks for your help!
0
Comment
Question by:tony01excel tony
4 Comments
 
LVL 5

Accepted Solution

by:
Yamaafg earned 1600 total points
ID: 41863920
Hi,

Try below code. Change the password from 123456 to whatever you would like it to be.You need to enter this code in the main workheet in vba and save your file as as xlsm.

Private Sub Workbook_SheetActivate(ByVal Sh As Object)
'to password protect Report Sheet
Dim xSheetName As String
xSheetName = "Report"
If Application.ActiveSheet.Name = xSheetName Then
    Application.EnableEvents = False
    Application.ActiveSheet.Visible = False
    xTitleId = "Please Enter The Password"
    response = Application.InputBox("Password", xTitleId, "", Type:=2)
    If response = "123456" Then
        Application.Sheets(xSheetName).Visible = True
        Application.Sheets(xSheetName).Select
    End If
End If
Application.Sheets(xSheetName).Visible = True
Application.EnableEvents = True
End Sub
0
 
LVL 19

Assisted Solution

by:Zaheer Iqbal
Zaheer Iqbal earned 400 total points
ID: 41863933
0
 

Author Closing Comment

by:tony01excel tony
ID: 41863940
Great, thanks for the quick help guys. The first solution with vba code worked well.
1
 
LVL 22

Expert Comment

by:Roy Cox
ID: 41864063
That code does not protect the sheet at all!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question