VBA保护Excel工作表但允许排序,自动过滤,图表,复制

时间:2013-11-20 10:47:43

标签: excel vba excel-vba

我的工作簿包含近25张,我想保护11张。我的保护标准如下:

1. User cannot delete or modify any cell
2. User should be able to use SORT, AUTOFILTER, drop down selection from COMBO BOXES
3. Most of the sheets contain charts, they should be updated as per the user selection
4. User should not be able to see the formulas in the formula bar
5. User should be able to copy the data

我已经尝试了Excel中的所有常规选项,它完成了上述所有工作,但它们使单元格保持解锁状态,这意味着用户可以删除内容

因此我希望这只能通过一个宏来实现,请帮助。

1 个答案:

答案 0 :(得分:0)

  

我已经尝试了Excel中的所有常规选项,它完成了上述所有工作,但它们使单元格保持解锁状态,这意味着用户可以删除内容

由于其他任何事情都适合你,我不会试图解决这些问题。已经拥有了,请在工作表代码区域中添加此代码

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
    On Error GoTo Whoa

    Dim rng As Range

    Application.EnableEvents = False

    For Each rng In Target
        If rng.Value = "" Then
            Application.Undo
            Exit For
        End If
    Next
Letscontinue:
    Application.EnableEvents = True
    Exit Sub
Whoa:
    MsgBox Err.Description
    Resume Letscontinue
End Sub