每当一个单元格被更改时,excel都会自动运行宏 [英] excel VBA run macro automatically whenever a cell is changed

查看:321
本文介绍了每当一个单元格被更改时,excel都会自动运行宏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



有关单元格将位于中,是否有简单的方法让Excel自动执行宏?工作表(BigBoard)。范围(D2)



我以为是一个简单的Google查询被证明是更复杂 - 每个样本涉及到(无论是那些)或颜色格式或任何其他数量的东西似乎是无关紧要的。

解决方案

是的,这可以通过使用工作表事件:



在Visual Basic编辑器中,通过双击名称打开您感兴趣的工作表(即BigBoard)的工作表在左上角的树。将以下代码放在模块中:

  Private Sub Worksheet_Change(ByVal Target As Range)
如果相交(目标, Me.Range(D2))没有,然后退出Sub
Application.EnableEvents = False'以防止无限循环
错误Goto Finalize'重新启用事件
MsgBox你改变了细胞!
Finalize:
Application.EnableEvents = True
End Sub


Is there a simple way to get Excel to automatically execute a macro whenever a cell is changed?

The cell in question would be in Worksheet("BigBoard").Range("D2")

What I thought would be a simple Google inquiry is proving to be more complicated - every sample involved intersects (whatever those are) or color formatting or any other number of things that appear to be irrelevant.

解决方案

Yes, this is possible by using worksheet events:

In the Visual Basic Editor open the worksheet you're interested in (i.e. "BigBoard") by double clicking on the name of the worksheet in the tree at the top left. Place the following code in the module:

Private Sub Worksheet_Change(ByVal Target As Range)
    If Intersect(Target, Me.Range("D2")) Is Nothing Then Exit Sub
    Application.EnableEvents = False 'to prevent endless loop
    On Error Goto Finalize 'to re-enable the events      
    MsgBox "You changed THE CELL!"
Finalize:        
    Application.EnableEvents = True
End Sub

这篇关于每当一个单元格被更改时,excel都会自动运行宏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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