Excel保护部分单元格的方法
时间:2022-08-17 07:43:28
文章介绍使用VBA来实现excel保护部分单元格,并给出基础操作保护部分单元格的链接。
本文介绍使用VBA代码来进行excel保护部分单元格的方法。
我们在需要进行excel保护部分单元格的工作表标签中,单击右键,选择“查看代码”,打开VBE编辑器,在编辑框输入下面的代码:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim b As Boolean
For Each c In Target ‘循环选定单元格
If c <> "" Then ‘如果单元格非空
b = True
Exit For ‘退出循环
End If
Next
ActiveSheet.Unprotect Password:="123" ‘撤消保护
If b = True Then
Target.Locked = True ‘锁定单元格
ActiveSheet.Protect Password:="123" ‘保护工作表,密码123
End If
End Sub
然后返回工作表中,当我们在单元格输入数据,马上就会对有数据内容的单元格进行保护,当我们试图要修改编辑时,只有通过撤销保护才能修改。
通过上面代码实现的excel保护部分单元格,就只对有数据内容的单元格进行保护,而空单元格是不受任何保护的,也就是可以正常随意的输入内容。
标签:代码,保护,单元格,工作,Excel函数
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
鲁大师检测cpu温度过高怎么办?
2023-11-12 16:09:28
![](https://img.aspxhome.com/file/2023/6/a321622_0s.jpg)
Win7系统怎么样清除上网痕迹?彻底删除上网记录的方法
2022-07-08 06:03:59
![](https://img.aspxhome.com/file/2023/27/a231567_0s.jpg)
wps表格怎样使用阅读技巧
2022-12-09 14:35:02
如何在pe中添加输入法
2023-05-06 22:35:16
Win7系统如何清空剪切板?
2023-12-22 11:27:06
![](https://img.aspxhome.com/file/2023/27/a230801_0s.jpg)
Win7系统文件损坏了怎么办?教你一招快速修复损坏系统文件
2023-05-16 12:19:03
![](https://img.aspxhome.com/file/2023/26/a228603_0s.png)
Excel RANK.EQ 函数 使用实例教程
2023-08-05 01:46:28
![](https://img.aspxhome.com/file/2023/1/a162841_0s.png)
Win10系统清理开始菜单使用记录的步骤
2023-12-16 17:10:46
![](https://img.aspxhome.com/file/2023/26/a226766_0s.jpg)
百度Hi怎么禁止公开个人日程闲忙状态?百度Hi个人日程闲忙状态禁止公开设置方法
2023-03-19 10:41:42
![](https://img.aspxhome.com/file/2023/7/a330221_0s.jpg)
flow短视频怎么玩?flow短视频玩法介绍
2022-07-30 01:21:17
![](https://img.aspxhome.com/file/2023/8/a334242_0s.jpg)
win10系统回收站损坏怎么修复
2023-06-06 12:53:40
![](https://img.aspxhome.com/file/2023/4/a309594_0s.jpg)
excel如何制作合同管理登记表
2023-07-01 14:00:14
![](https://img.aspxhome.com/file/2023/6/a156896_0s.png)
怎样用excel函数将数字转换为日期
2022-02-26 02:54:01
除了降噪,AirPods Pro 还有哪些亮点?
2022-03-10 16:16:25
![](https://img.aspxhome.com/file/2023/7/a196507_0s.jpg)
怎么预约到win10?win10预览版64/32位官方镜像下载地址
2022-04-06 18:22:34
![](https://img.aspxhome.com/file/2023/29/a251334_0s.jpg)
Pixelmator Pro 教程「27」,如何在 Pixelmator Pro 中移动图层?
2022-05-19 23:01:10
![](https://img.aspxhome.com/file/2023/6/a201906_0s.jpeg)
Win10电脑不能识别安卓设备怎么解决?
2023-07-17 18:15:33
![](https://img.aspxhome.com/file/2023/26/a220907_0s.jpg)
Win7旗舰版对电脑配置要求有哪些?
2022-06-16 10:32:19
![](https://img.aspxhome.com/file/2023/26/a229069_0s.png)
PPT演讲不会这12条要下岗
2022-07-31 05:58:17
![](https://img.aspxhome.com/file/2023/10/a352941_0s.jpg)
excel表格如何求和
2022-09-03 07:26:32