Hi there,
I recently had a problem whereby I couldn't sort my data within my worksheet due to my sheet being protected and also certain cells being password protected.
However I have now sorted that issue whereby I have highlighted the cells I need to sort and password protecting it - So when I need to sort, it will ask me for a password to unprotect this section.
When I do this however, after it sorts I want to change a cell that is initially suppose to be password protected - it changes without asking for the password - which is odd because the sheet is still protected.
Although the 2nd time I try it, it asks for a password!!
So my question is why doesn't it ask for a password the first time? & How do I get it to ask for a password the first time?
Here is the code which I altered in order to achieve this:
Thank you.
I recently had a problem whereby I couldn't sort my data within my worksheet due to my sheet being protected and also certain cells being password protected.
However I have now sorted that issue whereby I have highlighted the cells I need to sort and password protecting it - So when I need to sort, it will ask me for a password to unprotect this section.
When I do this however, after it sorts I want to change a cell that is initially suppose to be password protected - it changes without asking for the password - which is odd because the sheet is still protected.
Although the 2nd time I try it, it asks for a password!!
So my question is why doesn't it ask for a password the first time? & How do I get it to ask for a password the first time?
Here is the code which I altered in order to achieve this:
Code:
Option Explicit
Const sPassword As String = "Green"
Function ProtectSheet(bBoolean As Boolean, sSheetName As String) As Boolean
' -------------------------------------------------------------------------------------------
' Description: (Un)protects a given worksheet & Workbook
' Inputs: bBoolean: True = protect, False = unprotect, worksheet name
' Output: Boolean (True/False)
'--------------------------------------------------------------------------------------------
If bBoolean Then
Worksheets(sSheetName).EnableSelection = xlNoRestrictions
Worksheets(sSheetName).Protect Password:=sPassword, AllowFiltering:=True, AllowSorting:=True
Else
Worksheets(sSheetName).Unprotect Password:=sPassword
End If
ProtectSheet = True
End Function
Thank you.
