|
本帖最后由 szkent 于 2024-9-27 13:50 编辑
有请哪位达人,帮忙看看,
以下一段VBA代码结构,为何在修改单元格后,还是会触发SelectionChange事件?
应该是GetData子过程最后的Select 导致,
但不是已使用Application.EnableEvents = False,禁止了事件触发了吗?
为何还是在修改单元格后,会被触发了SelectionChange事件?
- '移动单元格位置就触发,
- Private Sub Worksheet_SelectionChange(ByVal Target As Range)
- Application.EnableEvents = False '关闭事件触发
- If (MemColumn = 1 Or MemColumn = 2) And Cells(MemRow, 1) <> nul And MemRow > 2 Then
- GetData MemRow, MemColumn
- Else
- Range(Worksheets("个股查询").Cells(MemRow, 2), Worksheets("个股查询").Cells(MemRow, 8)).ClearContents
- End If
- Application.EnableEvents = True '启动事件触发
- End Sub
- '修改单元格内容触发,
- Private Sub Worksheet_Change(ByVal Target As Range)
- Application.EnableEvents = False '关闭事件触发
- If (MemColumn = 1 Or MemColumn = 2) And MemRow > 2 And Cells(MemRow, 1) > 0 Then
- GetData MemRow, MemColumn
- Else
- Range(Worksheets("个股查询").Cells(MemRow, 1), Worksheets("个股查询").Cells(MemRow, 9)).ClearContents '清理单元格数据
- End If
- Application.EnableEvents = True '启动事件触发
- End Sub
- '更新数据
- Private Sub GetData(ByVal MemRow As Integer, MemColumn As Integer)
- Application.EnableEvents = False '关闭事件触发
- Worksheets("个股查询").Cells(MemRow, 1).Select
- End Sub
复制代码
|
|