vba 根据另一个单元格计算清除单元格内容
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13995119/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Clear cell content based on another cell calculation
提问by zozo23
this is an Excel/VBA question:
这是一个 Excel/VBA 问题:
I have a cell A1 in sheet2 linked cell A1
in sheet1
(simply A1='sheet1'!A1
). A1
in sheet1
is a data validation drop down menu.
我在sheet2链接的单元格A1
中有一个单元格A1 sheet1
(简单地A1='sheet1'!A1
)。A1
insheet1
是一个数据验证下拉菜单。
I want to clear the content of A2
in sheet2
every time the content of A1
in sheet2 changes/is updated. That is every time the value of A1
in sheet1
is changed using the drop down menu.
每次更改/更新 in sheet2的内容时,我都想清除A2
insheet2
的内容A1
。即每次使用下拉菜单更改A1
in的值时sheet1
。
I tried using a Worksheet_Change
event macro (which I do not fully understand) but it won't work with a cell that updates from a calculation. It also doesn't work if triggered from a cell from another worksheet (I tried linking it to cell A1
on sheet1
in this case).
我尝试使用Worksheet_Change
事件宏(我不完全理解),但它不适用于从计算更新的单元格。它还如果从另一个工作表(我试着将其链接到细胞的细胞触发的不工作A1
就sheet1
在这种情况下)。
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("A1")) Is Nothing Then Exit Sub
If Target.Count > 1 Then Exit Sub
Range("A2").ClearContents
End Sub
Can you think of a simple solution to clear the content of cell A2
in sheet2
when A1
in sheet2
updates?
你能想到一个简单的解决方案,以清除细胞的含量A2
在sheet2
当A1
在sheet2
更新?
回答by Siddharth Rout
This works for me...
这对我有用...
This code goes in the Sheet code area of Sheet1
此代码位于 Sheet1 的工作表代码区域
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("A1")) Is Nothing Then _
Sheets("Sheet2").Range("A2").ClearContents
End Sub