2017-04-13 56 views
0

我一直停留天以下几点:Excel的VBA - 过滤数据被锁定,密码

我想在特定行的密码锁的数据之后,还可以使用过滤器在这个数据上。

enter image description here

这是我走到这一步,但由于某种原因,这是行不通的。

任何输入将非常欢迎!

If logbook.Cells(row_index, 1) <> "" Then 
    ActiveSheet.Unprotect password:="mypassword" 
    logbook.Cells(row_index, 11).Value = "YES" 
    logbook.Cells(row_index, 1).EntireRow.Locked = True 
    ActiveSheet.Protect password:="mypassword", AllowFiltering:=True   
Else 
    Unload Me 
End If 
+0

'AllowSorting:= True,AllowFiltering:= True'将这些添加到'ActiveSheet.Protect'以启用排序和过滤。 – Luuklag

回答

0

如果您需要更改通过VBA的数据,你不需要取消保护。

只需使用UserInterfaceOnly:= True,并通过使用AllowFiltering:= True,您仍然可以过滤数据。像这样:

ActiveSheet.Protect Password:="mypassword", AllowFiltering:=True, UserInterfaceOnly:=True 
0

不知道如果我完全理解你的问题,但这个工程:

Sub Test() 

    'worksheet is protected 
    'read only operations 

    Sheets("tbl").Select 
    ActiveSheet.Unprotect Password:="mypassword" 

    'changes to worksheet 

    Sheets("Tabelle1").Select 
    ActiveSheet.Protect Password:="mypassword" 

End Sub 
+0

当工作表完全受保护时,我无法过滤数据。所以我需要找到一种方法来保护工作表,同时允许用户过滤数据。 –

+0

据我所知,被保护的纸张不能改变。要么读出你需要的数据并在其他地方操作,要么提升数据操作的保护。 –