vba 更改另一个单元格时清除单元格内容
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26843492/
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 contents when another cell is changed
提问by Matt
In Excel i have two dependent drop down lists that use an if statement to determine what is in the lists depending on what is in cell B8.
在 Excel 中,我有两个相关下拉列表,它们使用 if 语句根据单元格 B8 中的内容确定列表中的内容。
I would like to add in the VBA code if B8 is changed then clear any selected items in Cells B14 & B15
如果 B8 更改,我想添加 VBA 代码,然后清除单元格 B14 和 B15 中的所有选定项目
I have tried the following
我已经尝试了以下
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = Range("B8").Address Then
Range("B14:B15").Value = ""
End If
End Sub
But i get the error Ambiguous name detected:Worksheet_Change
但我得到了错误 Ambiguous name detected:Worksheet_Change
回答by Matt
Changed it to a SelectionChange
and it worked.
将其更改为 aSelectionChange
并且它起作用了。
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = Range("B8").Address Then
Range("B14:B15").Value = ""
End If
End Sub