Advanced Filter Protected Sheet

martipe1

Board Regular
Joined
Mar 16, 2007
Messages
71
I run advanced filter

ProtectSheets
... code
rngA.AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=Range( _
"WorkBalance"), CopyToRange:=Worksheets("Work").Range("R1"), Unique:=False

All sheets are protected with this procedure

Sub ProtectSheets()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
ws.Protect , userinterfaceonly:=True
Next ws
End Sub

And when I try to run my code receive the following error message:

"You cannot use this command on a protected sheet"

Why if the sheets are protected with userinterfaceonly:= True, my code gives me above mentioned error?

Thanks.
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Worksheets("Work").Range("R1")
The cells of R1 and below, where you write the filter result must be in unlock format to be able to write inside them.
Or unprotect the sheet, filter and then protect the sheet.
Try:

VBA Code:
With Worksheets("Work")
  .Unprotect
  rngA.AdvancedFilter Action:=xlFilterCopy, _
    CriteriaRange:=Range("WorkBalance"), _
    CopyToRange:=.Range("R1"), Unique:=False
  .Protect , userinterfaceonly:=True
End Sub
 
Upvote 0
Thank you very much for your answer.

That will do the trick, but still wondering why I need to unprotect a sheet if UserInterfaceOnly is supposed to protect the user interface but not for macros
 
Upvote 0
Try this:

VBA Code:
.Protect userinterfaceonly:=True
 
Upvote 0
Thank you for your reply.

At the beginning of my code I start protecting the sheets by calling the procedure ProtectSheets

VBA Code:
     ProtectSheets
             ... code
             rngA.AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=Range( _
             "WorkBalance"), CopyToRange:=Worksheets("Work").Range("R1"), Unique:=False

within that procedure, I protect sheets using UserInterfaceOnly

VBA Code:
Sub ProtectSheets()
      Dim ws As Worksheet
             For Each ws In ActiveWorkbook.Worksheets
                    ws.Protect , userinterfaceonly:=True
             Next ws
End Sub

I would assume with my code will be able to make changes to any protected sheet without the need to go through the process to unprotect/protect the sheet, but looks like I'm wrong and would like to know why.

Thanks
 
Upvote 0
I did some tests and with the advanced filter it does not work userinterfaceonly
 
Upvote 0
Solution
I did some tests and with the advanced filter it does not work userinterfaceonly
Hello,

I'm new to this forum but noticed a similar problem with the UserInterfaceOnly

If the worksheet is protected by a password that the user is not permitted to know, then there appears to be no way for a macro to insert anything into a protected cell without storing the password in the VBA code.

Has that been your experience?
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,728
Members
448,987
Latest member
marion_davis

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