根据其他单元格计算清除单元格内容 [英] Clear cell content based on another cell calculation

查看:62
本文介绍了根据其他单元格计算清除单元格内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个Excel/VBA问题:

this is an Excel/VBA question:

我在sheet2中有一个单元格A1,在 sheet1 中有一个链接的单元格 A1 (简称为 A1 ='sheet1'!A1 ). sheet1 中的 A1 是数据验证下拉菜单.

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 的内容时清除 sheet2 中的 A2 的内容.那就是每次使用下拉菜单更改 sheet1 中的 A1 的值时.

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.

我尝试使用 Worksheet_Change 事件宏(我不太了解的 ),但是它不适用于从计算中更新的单元格.如果是从另一个工作表的单元格触发的,它也不起作用(在这种情况下,我尝试将其链接到 sheet1 上的单元格 A1 ).

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).

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

您能想到一种简单的解决方案,当 sheet2 A1 时,清除 sheet2 中单元格 A2 的内容>更新?

Can you think of a simple solution to clear the content of cell A2 in sheet2 when A1 in sheet2 updates?

推荐答案

这对我有用...

此代码进入工作表Sheet1的工作表代码区域

This code goes in the Sheet code area of 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

这篇关于根据其他单元格计算清除单元格内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆