PROTECT A SHEET AND ENABLE AUTO FILTER - Code provided

Qroozn

Well-known Member
Joined
Mar 12, 2002
Messages
543
BELOW IS CODE TO ENABLE AUTOFILTER ON A worksheet when we dont want the user to adjust the sheet in any other way. I know people have always had trouble with it


With Worksheets("myworksheet")
.EnableSelection = xlUnlockedCells
.Protect DrawingObjects:=True, contents:=True, userInterfaceOnly:=True
.EnableAutoFilter = True
.Protect contents:=True,userInterfaceOnly:=True
End With
This message was edited by Qroozn on 2002-04-17 20:18
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Qroozin - VERY useful piece of code - thanks.

Having alittle trouble getting it to work.
I've entered "sheet1" in place of "myworkbook", and I'm getting error 1004.
it doesn't like something in the .Protect method.
Any ideas?
 
Upvote 0
Hi Blue, Q posted that code yesterday, works great. This is what I have in my workbook, hope it helps.

Private Sub Workbook_Open()
With Worksheets("sheet1")
.EnableSelection = xlUnlockedCells
.Protect DrawingObjects:=True, contents:=True, userInterfaceOnly:=True
.EnableAutoFilter = True
.Protect contents:=True, userInterfaceOnly:=True
End With
End Sub
 
Upvote 0
ok guys, what am I missing?
at first I thought the code would allow someone to go to a protected sheet, and set and use autofilters.
I now believe the code is designed to allow the developer to set the autofilters, THEN protect the worksheet, and have the autofilters active.

regardless-
I can't get it to work..
I've tried putting code into worksheet via VBE, and I've tried putting code into a button... no joy in either case.

please advise?
 
Upvote 0

Forum statistics

Threads
1,214,375
Messages
6,119,168
Members
448,870
Latest member
max_pedreira

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