简体   繁体   English

根据其他单元格计算清除单元格内容

[英]Clear cell content based on another cell calculation

this is an Excel/VBA question: 这是一个Excel / VBA问题:

I have a cell A1 in sheet2 linked cell A1 in sheet1 (simply A1='sheet1'!A1 ). 我在sheet2中有一个单元格A1sheet1链接了单元格A1 (简称A1='sheet1'!A1 )。 A1 in sheet1 is a data validation drop down menu. sheet1中的A1是数据验证下拉菜单。

I want to clear the content of A2 in sheet2 every time the content of A1 in sheet2 changes/is updated. 每当sheet2A1的内容更改/更新时,我想清除sheet2A2的内容。 That is every time the value of A1 in sheet1 is changed using the drop down menu. 这是每次使用下拉菜单更改sheet1A1值。

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. 我尝试使用Worksheet_Change事件宏( 我不完全理解 ),但它不适用于从计算更新的单元格。 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). 如果从另一个工作表中的单元格触发它也不起作用(在这种情况下我尝试将它链接到sheet1上的单元格A1 )。

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? 你能想到一个简单的解决方案,以清除单元格的内容的A2sheet2 ,当A1sheet2更新?

This works for me... 这对我有用......

This code goes in the Sheet code area of Sheet1 此代码位于Sheet1的Sheet代码区域中

Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Range("A1")) Is Nothing Then _
    Sheets("Sheet2").Range("A2").ClearContents
End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM