跳到主要内容

如何在Excel中将单元格设置为只读?

在许多情况下,您可能需要阻止其他人编辑工作表中的某些指定单元格。 本文提供了两种方法来帮助您将指定的单元格设置为只读,以便其他人无法编辑这些单元格(只读)。

通过保护工作表将单元格设置为只读
通过VBA代码将单元格设置为只读,而不保护工作表


通过保护工作表将单元格设置为只读

您只能锁定要使其变为只读的单元格,然后保护该工作表以实现此目的。 请执行以下操作。

1。 点击 当前工作表左上角的按钮选择整个单元格。

2。 按 按Ctrl + 1 同时打开 单元格格式 对话框。 在对话框中,取消选中 锁定 下框 的故事 选项卡,然后单击 OK 按钮。 看截图:

3.现在,选择要使其设为只读的单元格(此处选择范围为A1:C18的单元格)。 按 按Ctrl + 1 同时打开 单元格格式 对话框,检查 锁定 下框 的故事 选项卡并单击 OK 按钮。

4.继续单击 进入步骤三:发送 > 保护工作表。 看截图:

5.指定并确认您的密码以保护工作表,如下图所示。

现在,锁定范围内的单元格现在是只读的。 当您尝试编辑范围内的这些特定单元格时,将出现一个提示框,如下图所示。


在当前工作簿中同时用密码保护多个/所有工作表:

Microsoft Excel允许您一次用密码保护一个工作表。 在这里您可以使用 保护工作表取消保护工作表 的效用 Kutools for Excel 可以同时使用密码快速保护或取消保护当前工作簿中的多个工作表或所有工作表。
立即下载并试用! (30 天免费试用)


通过VBA代码将单元格设置为只读,而不保护工作表

如果您不想保护工作表以将单元格设置为只读。 本节中的VBA脚本将帮助您轻松解决此问题。

1.右键单击您需要将单元格设置为只读的工作表选项卡,然后单击 查看代码 从右键单击菜单中。

2.在开幕 Microsoft Visual Basic应用程序 窗口,将下面的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应用程序 窗口。

在当前工作表中单击单元格A3,A4或A5时,您将获得一个 Kutools for Excel 对话框,如下图所示,然后光标将自动移至右侧相邻单元格。

最佳办公生产力工具

🤖 Kutools 人工智能助手:基于以下内容彻底改变数据分析: 智能执行   |  生成代码  |  创建自定义公式  |  分析数据并生成图表  |  调用 Kutools 函数...
热门特色: 查找、突出显示或识别重复项   |  删除空白行   |  合并列或单元格而不丢失数据   |   不使用公式进行四舍五入 ...
超级查询: 多条件VLookup    多值VLookup  |   跨多个工作表的 VLookup   |   模糊查询 ....
高级下拉列表: 快速创建下拉列表   |  依赖下拉列表   |  多选下拉列表 ....
列管理器: 添加特定数量的列  |  移动列  |  切换隐藏列的可见性状态  |  比较范围和列 ...
特色功能: 网格焦点   |  设计图   |   大方程式酒吧    工作簿和工作表管理器   |  资源库 (自动文本)   |  日期选择器   |  合并工作表   |  加密/解密单元格    按列表发送电子邮件   |  超级筛选   |   特殊过滤器 (过滤粗体/斜体/删除线...)...
前 15 个工具集12 文本 工具 (添加文本, 删除字符,...)   |   50+ 图表 类型 (甘特图,...)   |   40+ 实用 公式 (根据生日计算年龄,...)   |   19 插入 工具 (插入二维码, 从路径插入图片,...)   |   12 转化 工具 (小写金额转大写, 货币兑换,...)   |   7 合并与拆分 工具 (高级组合行, 分裂细胞,...)   |   ... 和更多

使用 Kutools for Excel 增强您的 Excel 技能,体验前所未有的效率。 Kutools for Excel 提供了 300 多种高级功能来提高生产力并节省时间。  单击此处获取您最需要的功能...

产品描述


Office Tab 为 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