[VBA]_限制不能修改特定区域的值

本文提供了一个使用VBA在Excel中处理单元格变更及选择变更事件的示例代码。该代码定义了两个事件处理过程:`Worksheet_Change` 和 `Worksheet_SelectionChange`。通过这些事件,可以实现当指定范围内的单元格内容发生改变或被选中时,自动执行某些操作,如更新目标单元格的值。
摘要由CSDN通过智能技术生成
 1     Dim Volume
 2 Private Sub Worksheet_Change(ByVal Target As Range)
 3     Dim Ran1 As Range, Ran2 As Range, UnionRan As Range
 4     Set Ran1 = Sheets("    ").Range("    ")
 5     Set Ran2 = Sheets("    ").Range("    ")
 6     Set UnionRan = Application.Union(Ran1, Ran2)
 7     Dim Rng As Range
 8     Set Rng = Application.Intersect(Target, SPEC)
 9     If Not Rng Is Nothing Then
10         Target = Volume
11     End If
12 End Sub
13 
14 Private Sub Worksheet_SelectionChange(ByVal Target As Range)
15     Dim Ran1 As Range, Ran2 As Range, UnionRan As Range
16     Set Ran1 = Sheets("    ").Range("    ")
17     Set Ran2 = Sheets("    ").Range("    ")
18     Set UnionRan = Application.Union(Ran1, Ran2)
19     Dim Rng As Range
20     Set Rng = Application.Intersect(Target, SPEC)
21     If Not Rng Is Nothing Then
22         Volume = Target
23     End If
24 End Sub

 

转载于:https://www.cnblogs.com/heaven-liu/articles/2909633.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值