Question description:
This user has given permission to use the problem statement for this
blog.
I need help in below code
ub sbProtectAllSheets()
Dim pwd1 As String, pwd2 As String
pwd1 = InputBox("Please Enter the password")
If pwd1 = "" Then Exit Sub
pwd2 = InputBox("Please re-enter the password")
If pwd2 = "" Then Exit Sub
'Check if both the passwords are identical
If InStr(1, pwd2, pwd1, 0) = 0 Or _
InStr(1, pwd1, pwd2, 0) = 0 Then
MsgBox "You entered different passwords. No action taken"
Exit Sub
End If
For Each ws In Worksheets
ws.Protect Password:=pwd1
Next
MsgBox "All sheets Protected."
Exit Sub
End Sub
Solved by C. W. in 13 mins
This is the chat thread from the real Excelchat help session. It contains no private user
information.
Excelchat Expert
10/12/2017 - 03:59
thank you and welcome for selecting excelchat
Excelchat Expert
10/12/2017 - 03:59
please tell me sir which kind of help do you need?
User
10/12/2017 - 04:00
please help me to understand this coding
Excelchat Expert
10/12/2017 - 04:00
yes
Excelchat Expert
10/12/2017 - 04:00
1) sub is sub procedure where we have to write the function
Excelchat Expert
10/12/2017 - 04:01
and it applicable to a specific sheet of work book we have to define
Excelchat Expert
10/12/2017 - 04:01
2) then we have to define the variable
Excelchat Expert
10/12/2017 - 04:01
and give variable to datarange
Excelchat Expert
10/12/2017 - 04:02
then we give a value to variable
Excelchat Expert
10/12/2017 - 04:02
pwd1 = InputBox("Please Enter the password")
Excelchat Expert
10/12/2017 - 04:02
then if condition
Excelchat Expert
10/12/2017 - 04:03
If pwd1 = "" Then Exit Sub
pwd2 = InputBox("Please re-enter the password")
If pwd2 = "" Then Exit Sub
'Check if both the passwords are identical
If InStr(1, pwd2, pwd1, 0) = 0 Or _
InStr(1, pwd1, pwd2, 0) = 0 Then
Excelchat Expert
10/12/2017 - 04:03
and then msg box
Excelchat Expert
10/12/2017 - 04:03
for display the message
Excelchat Expert
10/12/2017 - 04:03
is it mae sence
User
10/12/2017 - 04:07
yes thanks go ahead
Excelchat Expert
10/12/2017 - 04:08
then sir
User
10/12/2017 - 04:08
we writw msg box
User
10/12/2017 - 04:08
MsgBox "You entered different passwords. No action taken"
Exit Sub
Excelchat Expert
10/12/2017 - 04:09
yes we have to write what we have to display in msg box
Excelchat Expert
10/12/2017 - 04:09
MsgBox "You entered different passwords. No action taken"
Exit Sub
Excelchat Expert
10/12/2017 - 04:09
then we have to close all the
Excelchat Expert
10/12/2017 - 04:09
sub
Excelchat Expert
10/12/2017 - 04:09
if
Excelchat Expert
10/12/2017 - 04:09
are you satisfied with this solution?
User
10/12/2017 - 04:10
yes
Excelchat Expert
10/12/2017 - 04:10
can i close this sesssion?
User
10/12/2017 - 04:10
yes
User
10/12/2017 - 04:10
thanks
Excelchat Expert
10/12/2017 - 04:10
please rate me 5 star
User
10/12/2017 - 04:10
yes
User
10/12/2017 - 04:10
you deserve
This is the output file from the real Excelchat help session:
This is an example of the expert help you can get. It contains no private user
information.