Allow sorting on a protected sheet (Is it possible)

drom

Well-known Member
Joined
Mar 20, 2005
Messages
566
Office Version
  1. 2021
  2. 2019
  3. 2016
  4. 2013
  5. 2011
  6. 2010
  7. 2007
Hi and thanks in advance !

I hace the following macro created recording a macro and adjusting a few things, eg

VBA Code:
Sub Macro2()

Dim wPass As String:        wPass = ""

    ActiveSheet.Unprotect
      Debug.Print Err, Err.Description
      'The inmediate window Shows 0
    
    ActiveSheet.Unprotect Password:=wPass
      Debug.Print Err, Err.Description
      'The inmediate window Shows 0
    
    ActiveSheet.Protect _
      UserInterfaceOnly:=True, _
        Password:=wPass, _
      DrawingObjects:=True, _
      Contents:=True, _
      Scenarios:=True, _
      AllowFormattingCells:=True, _
      AllowFormattingColumns:=True, _
      AllowFormattingRows:=True, _
      AllowInsertingColumns:=True, _
      AllowInsertingRows:=True, _
      AllowInsertingHyperlinks:=True, _
      AllowDeletingColumns:=True, _
      AllowDeletingRows:=True, _
      AllowSorting:=True, _
      AllowFiltering:=True, _
      AllowUsingPivotTables:=True
      
      Debug.Print Err, Err.Description
      'The inmediate window Shows 0
    
End Sub

My problem:
  • Sorting does not work

If I use :
VBA Code:
Sub Macro3()
    ActiveSheet.Unprotect
      Debug.Print Err, Err.Description
      'The inmediate window Shows 0    
    ActiveSheet.Unprotect Password:=wPass
      Debug.Print Err, Err.Description
      'The inmediate window Shows 0
    ActiveSheet.Protect _
      AllowSorting:=True
    
      Debug.Print Err, Err.Description
      'The inmediate window Shows 0
End Sub

This shorter macro, easyer to check stil not working

What am I missing

Itm it possible to sort in a protected tab/sheet ?
 
Hmmm...
VBA Code:
Option Explicit

Sub Macro1()
    Dim wPass As String: wPass = ""
   
    With ActiveSheet
        .Unprotect Password:=wPass
   
        With .Range("A1:D100")
            .Locked = False
            .FormulaHidden = False
        End With
   
        .Protect Password:=wPass, UserInterfaceOnly:=True, _
            DrawingObjects:=True, Contents:=True, Scenarios:=True, _
            AllowSorting:=True, AllowFiltering:=True
    End With
   
End Sub
Protection.AllowSorting property (Excel)
 
Last edited:
Upvote 0
Solution
Hmmm...
VBA Code:
Option Explicit

Sub Macro1()
    Dim wPass As String: wPass = ""
  
    With ActiveSheet
        .Unprotect Password:=wPass
  
        With .Range("A1:D100")
            .Locked = False
            .FormulaHidden = False
        End With
  
        .Protect Password:=wPass, UserInterfaceOnly:=True, _
            DrawingObjects:=True, Contents:=True, Scenarios:=True, _
            AllowSorting:=True, AllowFiltering:=True
    End With
  
End Sub
Protection.AllowSorting property (Excel)
Is it possible to do this without putting .Locked = False ?
I am using tables and I cant unlock the columns with formulas

Thanks
 
Upvote 0
No, you can only sort cells that are unlocked.
 
Upvote 0
You read the Help on the link provided?
Sorting can only be performed on unlocked or unprotected cells in a protected worksheet.
 
Upvote 0

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
Back
Top