Password protected cells aren't working after using Sorting Filter

sdhutty

Board Regular
Joined
Jul 15, 2016
Messages
207
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:

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. :)
 

Some videos you may like

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).

Watch MrExcel Video

Forum statistics

Threads
1,122,832
Messages
5,598,361
Members
414,233
Latest member
WolverineNurse

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
Top