vba 无法对带有锁定单元格的受保护工作表上的数据进行排序或过滤
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9182031/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
unable to sort or filter data on a protected sheet with locked cells
提问by user793468
I have a sheet which is protected with locked cells. Even after checking the "sort" and "Auto filter" option while protecting the sheet, I am still unable to sort/filter the data.
我有一张用锁定的单元格保护的工作表。即使在保护工作表的同时选中“排序”和“自动过滤”选项后,我仍然无法对数据进行排序/过滤。
I get the following message when I click the Sort button:
单击“排序”按钮时,我收到以下消息:
The cell or chart that you are trying to change is protected and therefore read-only. To modify a protected cell or chart, first remove protection...
您尝试更改的单元格或图表受到保护,因此是只读的。要修改受保护的单元格或图表,首先删除保护...
Am I missing something?
我错过了什么吗?
Thanks in advance
提前致谢
回答by Doug Glancy
Even with the settings as you mentioned, you can only sort if all the cells to be sorted are unlocked. You can autofilter even if the cells are locked, but you can't turn autofiltering on and off.
即使使用您提到的设置,您也只能在所有要排序的单元格都已解锁的情况下进行排序。即使单元格被锁定,您也可以自动过滤,但您无法打开和关闭自动过滤。
You're post is tagged excel-vba
, so I'll mention that you can protect the sheet in code using UserInterfaceOnly:=True and then you can do all of the above using VBA:
您的帖子被标记为excel-vba
,所以我会提到您可以使用 UserInterfaceOnly:=True 在代码中保护工作表,然后您可以使用 VBA 执行上述所有操作:
Activesheet.Protect userinterfaceonly:=True, AllowSorting:=True, AllowFiltering:=True