×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

VBA Allow features in a protected worksheet

VBA Allow features in a protected worksheet

VBA Allow features in a protected worksheet

(OP)
I’m looking to protect a worksheet, but allow grouped columns to be collapsed or expanded. Also would like to allow the user to set filters and hide columns. I put the below code in the “ThisWorkbook” object. This protected the worksheet but not with a password. The VBA below allowed the grouped columns to expand and collapse. It also allowed columns to be hidden, but did not allow filtering. Not an expert with VBA so looking for help. Also, if I decide to password protect, where would I enter that in the VBA?
Thanks for your help.

Private Sub Workbook_Open()
With Worksheets("Sheet1")
.EnableOutlining = True
.Protect UserInterfaceOnly:=True
.Protect AllowFiltering:=True
.Protect AllowFormattingColumns:=True
End With
End Sub

RE: VBA Allow features in a protected worksheet

>but did not allow filtering

SWell,. it does - but only if you've already got a simple filter, which Microsoft often refer to as an autofilter (basically the filter applied when you click the funnel icon) in place; you can change it. And it allows you to apply a n Advanced filter. What you can't do is ADD a NEW simple filter. Or, as the MS documentations says:

Users can change filter criteria but can not enable or disable an auto filter. Users can set filters on an existing auto filter

RE: VBA Allow features in a protected worksheet

(OP)
Thanks for the reply. I created filters in the first few columns. When I reopened the file, the filters were there but did not function. I clicked on the filter arrow and there is no drop down.

RE: VBA Allow features in a protected worksheet

'Protect' method has some optional arguments, password among others, you can use them in single line:
With Worksheets("Sheet1")
    .EnableOutlining = True
    .Protect Password:="YourPassword", UserInterfaceOnly:=True, AllowFiltering:=True, AllowFormattingColumns:=True
End With 

combo

RE: VBA Allow features in a protected worksheet

(OP)
Thank you very much. Works for me.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close