Excel VBA:限制Excel工作表中的编辑区域
我想限制用户在 Ms Excel 工作表中编辑范围。
Scenario:
| A | B | C | D | E | F | G | H | I | J | ... IV
-------------------------------------------
1 | | | | | | | | | | |
-------------------------------------------
2 | | | | | | | | | | |
-------------------------------------------
3 | | | | | | | | | | |
-------------------------------------------
4 | | | | | | | | | | |
-------------------------------------------
...
65536
在上面的电子表格中,用户应该有权编辑 Column A
到 Column H
范围。 Column I to IV
用户不应允许编辑任何文本或任何内容。行数没有限制。
谢谢 :)
I want to restrict the users to edit range in Ms Excel sheet.
Scenario:
| A | B | C | D | E | F | G | H | I | J | ... IV
-------------------------------------------
1 | | | | | | | | | | |
-------------------------------------------
2 | | | | | | | | | | |
-------------------------------------------
3 | | | | | | | | | | |
-------------------------------------------
4 | | | | | | | | | | |
-------------------------------------------
...
65536
In the above spreadsheet user should have access to edit the range Column A
to Column H
. Column I to IV
users should not allow to edit any text or anything. No restriction on number of rows.
Thanks :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
要以编程方式执行此操作,请在模块中尝试此操作(并对其进行调整以满足您的需求):
To do this programatically, try this in a module (and adapt it to suit your needs):
分三步
1) 选择整个工作表。格式->锁定单元格->删除所有单元格的锁定。 (默认情况下,所有单元格最初都“锁定”)
2) 选择所需的锁定列。格式->锁定单元格->应用锁定(这是声明性的,您没有锁定任何内容,只是声明下一步要锁定的内容)
3)格式->应用锁定保护工作表。 (这会触发真正的保护)
你就完成了。
华泰
In three steps
1) Select the whole sheet. Format->Lock Cells->Remove locking for all cells. (All cells are initially "locked" by default)
2) Select your desired locking columns. Format->Lock Cells->Apply Locking (This is declarative, you are not locking nothing, just declaring what you will lock in the next step)
3) Format-> Protect Worksheet. (This trigger the real protection)
You are done.
HTH
sasfrog 和 belisarius 提案的一些替代方案(只是为了丰富您的选择):
a)您也可以隐藏列 K:IV,并保护工作表以防止取消隐藏
b) 使用“工具”、“保护”、“允许用户编辑范围”选项,将范围 $a:$h 定义为属于Everyone 组的用户无需密码即可编辑,然后保护您的工作表。我喜欢那个。
不要忘记,任何涉及 Excel 内置保护的解决方案都会阻止您的用户插入/删除行。
c) 使用 VBA(不会阻止删除/插入行):
Some alternatives to sasfrog and belisarius proposals (just to enrich your options):
a) you may also just HIDE columns K:IV, and protect the worksheet to prevent unhiding
b) Using the Tools, Protection, "Allow users to edit ranges" option, define range $a:$h as editable without password for users belonging to Everyone group, then protect your sheet. I like that one.
Don't forget that any solution involving Excel built in protection will prevent your users from inserting/deleting rows.
c) Using VBA (would not prevent deleting/inserting rows):
将限制用户可以选择的单元格。
will restrict what cells the user can select.
应修改 iDevlop 的选项 c) 以防止无限循环:
这仍然允许用户将多单元格复制粘贴到指定的相交范围中。还没有弄清楚这一点。
iDevlop's option c) should be modified to prevent an infinite loop:
This will still allow a user to make a multi-cell copy paste into your specified Intersect range. Havent figured that one out.