跳到主要內容

如何在Excel中將單元格設置為只讀?

在許多情況下,您可能需要阻止其他人編輯工作表中的某些指定單元格。 本文提供了兩種方法來幫助您將指定的單元格設置為只讀,以便其他人無法編輯這些單元格(只讀)。

通過保護工作表將單元格設置為只讀
通過VBA代碼將單元格設置為只讀,而不保護工作表


通過保護工作表將單元格設置為只讀

您只能鎖定要使其變為只讀的單元格,然後保護該工作表以實現此目的。 請執行以下操作。

1。 點擊 當前工作表左上角的按鈕選擇整個單元格。

2。 按 按Ctrl + 1 同時打開 單元格格式 對話框。 在對話框中,取消選中 鎖定 下框 保護的故事 選項卡,然後單擊 OK 按鈕。 看截圖:

3.現在,選擇要使其設為只讀的單元格(此處選擇範圍為A1:C18的單元格)。 按 按Ctrl + 1 同時打開 單元格格式 對話框,檢查 鎖定 下框 保護的故事 標籤並點擊 OK 按鈕。

4.繼續單擊 回顧 > 保護工作表。 看截圖:

5.指定並確認您的密碼以保護工作表,如下圖所示。

現在,鎖定範圍內的單元格現在是只讀的。 當您嘗試編輯範圍內的這些特定單元格時,將出現一個提示框,如下圖所示。


在當前工作簿中同時用密碼保護多個/所有工作表:

Microsoft Excel允許您一次用密碼保護一個工作表。 在這裡您可以使用 保護工作表取消保護工作表 的效用 Excel的Kutools 可以同時使用密碼快速保護或取消保護當前工作簿中的多個工作表或所有工作表。
立即下載並試用! (30 天免費試用)


通過VBA代碼將單元格設置為只讀,而不保護工作表

如果您不想保護工作表以將單元格設置為只讀。 本節中的VBA腳本將幫助您輕鬆解決此問題。

1.右鍵單擊您需要將單元格設置為只讀的工作表選項卡,然後單擊 查看代碼 從右鍵單擊菜單中。

2.在開幕 Microsoft Visual Basic for Applications 窗口,將下面的VBA代碼複製並粘貼到“代碼”窗口中。

VBA代碼:在Excel中將單元格設置為只讀

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.Column = 1 Then
        If Target.Row = 3 Or Target.Row = 4 Or Target.Row = 5 Then
            Beep
            Cells(Target.Row, Target.Column).Offset(0, 1).Select
            MsgBox Cells(Target.Row, Target.Column).Address & " cannot be selected and edited as it is a read-only cell", _
            vbInformation, "Kutools for Excel"
        End If
    End If
End Sub

備註:此代碼只能使指定的單元格在一列中為只讀。 在此代碼中,它將使單元格A3,A4和A5在當前工作表中為只讀。

3。 按 其他 + Q 關閉鍵 Microsoft Visual Basic for Applications 窗口。

在當前工作表中單擊單元格A3,A4或A5時,您將獲得一個 Excel的Kutools 對話框,如下圖所示,然後光標將自動移至右側相鄰單元格。

最佳辦公生產力工具

🤖 Kutools 人工智慧助手:基於以下內容徹底改變數據分析: 智慧執行   |  生成代碼  |  建立自訂公式  |  分析數據並產生圖表  |  呼叫 Kutools 函數...
熱門特色: 尋找、突出顯示或識別重複項   |  刪除空白行   |  合併列或儲存格而不遺失數據   |   沒有公式的回合 ...
超級查詢: 多條件VLookup    多值VLookup  |   跨多個工作表的 VLookup   |   模糊查詢 ....
高級下拉列表: 快速建立下拉列表   |  依賴下拉列表   |  多選下拉列表 ....
欄目經理: 新增特定數量的列  |  移動列  |  切換隱藏列的可見性狀態  |  比較範圍和列 ...
特色功能: 網格焦點   |  設計圖   |   大方程式酒吧    工作簿和工作表管理器   |  資源庫 (自動文字)   |  日期選擇器   |  合併工作表   |  加密/解密單元格    按清單發送電子郵件   |  超級濾鏡   |   特殊過濾器 (過濾粗體/斜體/刪除線...)...
前 15 個工具集12 文本 工具 (添加文本, 刪除字符,...)   |   50+ 圖表 類型 (甘特圖,...)   |   40+ 實用 公式 (根據生日計算年齡,...)   |   19 插入 工具 (插入二維碼, 從路徑插入圖片,...)   |   12 轉化 工具 (數字到單詞, 貨幣兌換,...)   |   7 合併與拆分 工具 (高級合併行, 分裂細胞,...)   |   ... 和更多

使用 Kutools for Excel 增強您的 Excel 技能,體驗前所未有的效率。 Kutools for Excel 提供了 300 多種進階功能來提高生產力並節省時間。  點擊此處獲取您最需要的功能...

產品描述


Office選項卡為Office帶來了選項卡式界面,使您的工作更加輕鬆

  • 在Word,Excel,PowerPoint中啟用選項卡式編輯和閱讀,發布者,Access,Visio和Project。
  • 在同一窗口的新選項卡中而不是在新窗口中打開並創建多個文檔。
  • 將您的工作效率提高 50%,每天為您減少數百次鼠標點擊!
Comments (12)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Very useful!!
This comment was minimized by the moderator on the site
Hi! How about if i want to just make 1 column editable and the rest uneditable? Thanks!
This comment was minimized by the moderator on the site
Hi Jac,
Please click on the column header to select the whole column, then do the steps mentioned in the post to unlock the column cells then protect the worksheet.
This comment was minimized by the moderator on the site
every usefull, thank you with gratitude
This comment was minimized by the moderator on the site
Thanks for the quick guidance.
This comment was minimized by the moderator on the site
Hi



I have mulipe sheets Menu ( option A1& A2) , A1 and A2 and VIEW work sheets ( where i will have BROWSE button) .



1. In menu i will select A1..

2. it will go to VIEW sheet ( which is working fine) till now ..

3. when i click on the BROWSE in the VIEW sheet A1 shee shoulf get displayed and the content present in the cells should be non editable..



Could you please help..
This comment was minimized by the moderator on the site
Good day,
Supposing there is a Command Button (ActiveX Control) in the View sheet. After inserting the below VBA into the worksheet code window, click on the button, in a popping up Kutools for Excel dialog box, specify a password to protect the sheet A1. Then sheet A1 is opened and non editable.

Private Sub CommandButton1_Click()
Dim xSheet As Worksheet
Dim xStr As String
On Error Resume Next
Set xSheet = Sheets("A1")
If xSheet Is Nothing Then Exit Sub
xSheet.UsedRange.Locked = True
xStr = Application.InputBox("Please specify a password to protect the sheet A1", "KuTools for Excel", , , , , , 2)
If xStr = False Or xStr = "" Then Exit Sub
xSheet.Protect xStr
xSheet.Activate
End Sub
This comment was minimized by the moderator on the site
i just want to make few cells of a book locked for input, only they shows the result as i programmed them to do so
This comment was minimized by the moderator on the site
Hey, Thanks a lot for this steps.


However, what if I want to copy the values in the cells that I have locked?
This comment was minimized by the moderator on the site
Dear Yahia,
The locked cells in a protected worksheet can't be copied.
This comment was minimized by the moderator on the site
Very Helpful. Thanks ! :D
This comment was minimized by the moderator on the site
Dear i want to protect the hidden cells from by copying to the new sheet, is there any option in the excel sheet for that. Means no can able to view the formulaes after copying from one sheet to other sheet.
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations