Excel 或 下一个c 如果不过滤旧状态,则 如果不过滤,那么 ws.Protect 其他的 ws.Unprotect 如果结束 如果结束 设置ws=Nothing 端接头
我有一个类似的问题。我希望用户能够在 受保护的工作表。但用户无法编辑该表。我在上面完成了, 使用下面的vba代码:Excel 或 下一个c 如果不过滤旧状态,则 如果不过滤,那么 ws.Protect 其他的 ws.Unprotect 如果结束 如果结束 设置ws=Nothing 端接头,excel,vba,Excel,Vba,我有一个类似的问题。我希望用户能够在 受保护的工作表。但用户无法编辑该表。我在上面完成了, 使用下面的vba代码: Range("Table3").Select Selection.Locked = True Selection.FormulaHidden = False ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _ , allowfiltering:=True
Range("Table3").Select
Selection.Locked = True
Selection.FormulaHidden = False
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _
, allowfiltering:=True
在以下代码中,我使用VBA过滤了代码:
Range("Table3[[#Headers],[Aantal4]]").Select
ActiveSheet.ListObjects("Table3").Range.AutoFilter Field:=8, Criteria1:= _
Array("1", "12", "2", "24", "4", "6"), Operator:=xlFilterValues
我建议您重新阅读Excel帮助om
工作表Proptect
,特别是关于允许参数wrt受保护的工作表和锁定的单元格。AllowSorting:“排序范围内的每个单元格都必须解锁或不受保护”AllowFiltering:“用户可以更改筛选条件,但不能启用或禁用自动筛选”谢谢,这很遗憾,因为我需要能够阻止某些内容,但允许用户进行排序和筛选。有什么想法吗?1)确保你的范围不与其他范围重叠。2.)在对您的区域应用锁定之前,解锁工作表中的所有单元格。3.“当工作表受到保护时,要过滤的单元格必须解锁。”…所以不要将这些“过滤单元格”作为锁定范围的一部分。问题是如何使用VBA执行该操作。你的答案是错误的,这正是我想要的——使用locked
标志是一个巧妙的技巧。这应该是答案
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Locked = True Then
Application.EnableEvents = False
Application.Undo
Application.EnableEvents = True
End If
End Sub
BioSum.Unprotect "letmein"
'<Your function here>
BioSum.Cells(1, 1).Activate
BioSum.Protect "letmein"
> Protect Sheet
> Select Locked Cells (already selected)
> Select unlocked Cells (already selected)
> (and either) select Sort (or) Auto Filter
Private Sub Worksheet_Change(ByVal Target As Range)
For Each i In Target
If i.Locked = True Then
Application.EnableEvents = False
Application.Undo
Application.EnableEvents = True
MsgBox "Your action was undone because it made changes to a locked cell.", , "Action Undone"
Exit For
End If
Next i
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Const FilterRow = 1
Dim c As Range
Dim NotFilterRow As Boolean
Dim oldstate As Boolean
Dim ws As Worksheet
Set ws = ActiveSheet
oldstate = ws.ProtectContents
NotFilterRow = False
For Each c In Target.Cells
NotFilterRow = c.Row <> FilterRow
If NotFilterRow Then Exit For
Next c
If NotFilterRow <> oldstate Then
If NotFilterRow Then
ws.Protect
Else
ws.Unprotect
End If
End If
Set ws = Nothing
End Sub
Range("Table3").Select
Selection.Locked = True
Selection.FormulaHidden = False
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _
, allowfiltering:=True
Range("Table3[[#Headers],[Aantal4]]").Select
ActiveSheet.ListObjects("Table3").Range.AutoFilter Field:=8, Criteria1:= _
Array("1", "12", "2", "24", "4", "6"), Operator:=xlFilterValues