保護單元格,但允許下拉列表工作

保護單元格,但允許下拉列表工作

我想保護其中有下拉列表的單元格,但我仍然希望下拉列表能夠工作。

當我嘗試保護它時,用戶無法使用下拉清單來選擇其他項目或巨集。

我收到此錯誤訊息

「您嘗試變更的儲存格或圖表受保護,因此是唯讀的。若要修改受保護的儲存格或圖表,請先使用「不受保護的工作表」指令(「審查」標籤、「變更」群組)刪除保護。

答案1

下拉式選單附加到單元格。這就是它儲存資料的地方。驗證將保證數據有效。

如果您還沒有這樣做,請確保單元格未鎖定。右鍵單擊該單元格,然後按一下“設定儲存格格式”,然後轉到“保護”標籤。應取消選取“鎖定”複選框。

答案2

我認為這個問題可能被誤解了。如果是這樣,並且如果我的解釋正確的話,這裡有一個解決方案。

Excel 實際上允許電子表格使用者覆蓋使用驗證清單的儲存格;如果清單包含值“Apple”、“Peach”和“Orange”,標準操作允許使用者在未受保護的儲存格中鍵入“Broccoli”,就像沒有附加驗證清單一樣。但是,保護單元格和工作表會停用從驗證清單中選擇項目的功能,這可能是一個問題。

如果這是問題所在,這裡有一個解決方案:

1.  Format the cell using the validation list so it's 
    unprotected. 
2.  With the cursor positioned at that cell, open the 
    Validation menu origintally used to identify the validation 
    list. 
3.  On the Settings tab of the Data Validation window pane,
    be sure that "ignore blank" is unchecked, and 
    continue to leave that window pane open. 
4.  On the "Error alert" tab of the Data Validation window
    pane:  
      a) Be sure "Show error alert after invalid data is
         entered" is checked. 
      b) Select "Stop" under the "Style" heading.
      c) Give your error alert a name under "Title"; this 
         can be anything, but a short title is best. 
      d) Under "Error message", type a short message that you
         want to appear if a user tries to manually type a value
         in the cell - something like "Please use the drop-down
         menu provided to select a value for this cell."
      e) Click "OK". 

這將阻止人們在旨在使用資料驗證的儲存格中輸入他們想要的任何內容,即使工作表不受保護。不過,您可能想要保護工作表,以防止資料驗證清單本身的意外更新。

答案3

在我的電腦(運行 Excel 2010 的 PC)上,下拉清單本身實際上似乎直接附加到右側的儲存格。因此,如果我想要 A7 中的下拉列表,我必須同時解鎖 A7 和 B7。

這可能是個錯誤,但這是一個相對簡單的修復。

答案4

在受保護的工作表中:

將以下連結貼到工作簿中

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)

    Dim wsh As Variant
    For Each wsh In Worksheets(Array("Sheet1"))
        wsh.EnableOutlining = True
        wsh.Protect UserInterfaceOnly:=True, Password:="", _
            DrawingObjects:=False, _
    Contents:=True, _
    Scenarios:=True, _
    AllowFormattingCells:=False, _
    AllowFormattingColumns:=False, _
    AllowFormattingRows:=False, _
    AllowInsertingColumns:=False, _
    AllowInsertingRows:=False, _
    AllowInsertingHyperlinks:=False, _
    AllowDeletingColumns:=False, _
    AllowDeletingRows:=False, _
    AllowSorting:=False, _
    AllowFiltering:=False, _
    AllowUsingPivotTables:=False
    Next wsh

Dim Oldvalue As String
Dim Newvalue As String

On Error GoTo Exitsub
If Target.Address = "$C$2" Then 'As required
    If Target.SpecialCells(xlCellTypeAllValidation) Is Nothing Then
    GoTo Exitsub
    Else: If Target.Value = "" Then GoTo Exitsub Else
        Application.EnableEvents = False
        Newvalue = Target.Value
        Application.Undo
        Oldvalue = Target.Value
        If Oldvalue = "" Then
            Target.Value = Newvalue
        Else
            Target.Value = Oldvalue & ", " & Newvalue
        End If
    End If
End If


Exitsub:
Application.EnableEvents = True

End Sub

相關內容