Excel VBA活动 [英] Excel VBA Events

查看:100
本文介绍了Excel VBA活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Excel VBA有一点新意。我目前设计了VBA代码来生成一个Vlookup,它基于另一个工作表中的ref数据填充数据表中列(称为Y列)中的数据,并在同一工作表的另一个列(列X)中填充数据。这是我在Workbook_Open事件上执行的。



然而,当需要在特定行中更改列X的值时,我还需要更新列Y的值。另外,如果添加了一个行,我也需要提供一个Y值。然而,我似乎找不到相同的适当的事件,禁止在工作表级别的选择更改的事件,当您更改所选的单元格时触发。

解决方案

尝试工作表更改事件...为了确保列X中发生的某些事情,您可以这样写一些这样的信息:

  Private Sub Worksheet_Change(ByVal Target As Range)
如果不相交(目标,范围(X:X))没有,然后
MsgBox(嗨 )
如果
End Sub

希望这有助于


I'm a little new to Excel VBA. I've currently designed VBA code to produce a Vlookup that populates data in a column(say column Y) in my datasheet based on ref data in another sheet, and a filled value in another column (column X) of the same sheet. This I'm performing on the Workbook_Open event.

I need to, however, also be able to update column Y's value when column X's value is changed in a particular row. Also, if an additional row is added, I need to be able to provide a Y value for that too. However, I can't seem to find an appropriate event for the same, barring the selection changed event at Worksheet level, which is triggered when u change which cell you've selected.

解决方案

Try the worksheet change event... To ensure something happened in Column X, you would write somethign like this:

Private Sub Worksheet_Change(ByVal Target As Range)
 If Not Intersect(Target, Range("X:X")) Is Nothing Then
   MsgBox ("Hi")
 End If
End Sub

Hope this helps

这篇关于Excel VBA活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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