Data sort function and menu bar is greyed out after macro running

Apple08

Active Member
Joined
Nov 1, 2014
Messages
450
Hi All

I have a macro to protect columns A to K for sheets A to E, however after the macro running, the data sort function in the menu bar is greyed out. Please could anyone help how to fix it. Thanks.

VBA Code:
Sub ProtectA_K()


Sheets("A").Select
    Columns("A:K").Select
    Selection.Locked = True
    Selection.FormulaHidden = False
    ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:= _
        False, AllowFormattingCells:=True, AllowFormattingColumns:=True, _
        AllowFormattingRows:=True, AllowInsertingHyperlinks:=True, AllowFiltering _
        :=True
 
 Sheets("B").Select
    Columns("A:K").Select
    Selection.Locked = True
    Selection.FormulaHidden = False
    ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:= _
        False, AllowFormattingCells:=True, AllowFormattingColumns:=True, _
        AllowFormattingRows:=True, AllowInsertingHyperlinks:=True, AllowFiltering _
        :=True
        
Sheets("C").Select
    Columns("A:K").Select
    Selection.Locked = True
    Selection.FormulaHidden = False
    ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:= _
        False, AllowFormattingCells:=True, AllowFormattingColumns:=True, _
        AllowFormattingRows:=True, AllowInsertingHyperlinks:=True, AllowFiltering _
        :=True
        
Sheets("D").Select
    Columns("A:K").Select
    Selection.Locked = True
    Selection.FormulaHidden = False
    ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:= _
        False, AllowFormattingCells:=True, AllowFormattingColumns:=True, _
        AllowFormattingRows:=True, AllowInsertingHyperlinks:=True, AllowFiltering _
        :=True
        
Sheets("E").Select
    Columns("A:K").Select
    Selection.Locked = True
    Selection.FormulaHidden = False
    ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:= _
        False, AllowFormattingCells:=True, AllowFormattingColumns:=True, _
        AllowFormattingRows:=True, AllowInsertingHyperlinks:=True, AllowFiltering _
        :=True
    
    Sheets("A").Select
    Range("A2").Select

End Sub
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
If you protect then you cant sort locked cells. You would be able to sort unlocked cells provided you had checked the checkbox.
 
Upvote 0
Thanks Steve, indeed I have another macro running before that one, please see below the macro:

VBA Code:
Dim ws As Worksheet
    For Each ws In ActiveWorkbook.Worksheets
        With ws
            .Cells.Locked = False
            .Cells.FormulaHidden = False
        End With
    Next ws
    
Call ProtectA_K

End Sub
 
Upvote 0
You will need AllowSorting:=True also. After that it should allow you to sort the unlocked (therefore unprotected) cells. Still wont sort the locked cells.
 
Upvote 0

Forum statistics

Threads
1,215,004
Messages
6,122,659
Members
449,091
Latest member
peppernaut

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