Filter in table not working after protecting sheet using macro

1q2w3

New Member
Joined
Mar 20, 2020
Messages
24
Office Version
  1. 365
Platform
  1. Windows
Hi,

I have a set of macro i used to hide rows in a table based on a selected drop box and is working fine after i added the protect sheet macro.

For example:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
ActiveSheet.Unprotect Password:="password"
Dim A, Criteria As Range
Set A = Range("A1")
Set Criteria = Range("B1")
Select Case A
Case Is = "Show All":
Rows("5:100").EntireRow.Hidden = False
Case is = "Show B"
Rows("50:100).EntireRow.Hidden = True
End Select
ActiveSheet.protect Password:="password"
End Sub

However, within the table, when i attempt to use the filter function, it stopped working. Nothing happens when I clicked on it. But when i removed the ActiveSheet.protect password, then it works fine again.

How can I make the filter work even under protected condition?

Thanks :)
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Hi,

You have to add permissions to use autofilter after you enable protection:

This will allow you to use autofilter:
AllowFiltering:=True

(note I didn't use password in my piece of code)


VBA Code:
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _
        , AllowFiltering:=True
 
Upvote 0

Forum statistics

Threads
1,214,973
Messages
6,122,534
Members
449,088
Latest member
RandomExceller01

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