Excel VBA Events

2019-09-12 09:32发布

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.

1条回答
唯我独甜
2楼-- · 2019-09-12 10:06

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

查看更多
登录 后发表回答