Solved

How can I set password for a sheet in excel

Posted on 2016-10-28
4
33 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 400 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 100 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 17

Expert Comment

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

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Drop Down List with Unique/Distinct Values (Part II - ComboBox or ListBox and Data Validation List Bonus!) David Miller (dlmille) Intro This article focuses on delivering unique, sorted lists to list objects (e.g., ComboBox, ListBox) and Dat…
Approximate matching with VLOOKUP and MATCH seems to me to be a greatly under-used technique, and one which is vital for getting good performance out of large lookups. Until recently I would always have advised using an exact match for simplicity an…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now