VBA Excel使用currentRegion而不使用selectionChanged触发 [英] VBA excel using currentRegion without selectionChanged firing

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

问题描述

我有以下感觉:每当用户选择某个单元格时,我就会将一个表从隐藏的工作表复制到活动的工作表.然后,当用户更改选择时,我需要清除复制表的内容并从隐藏工作表中复制另一个表.

I have the following senario: whenever the user selects a certain cell, I'm copying a table from a hidden sheet to the active sheet. Then, when the user changes his selection, I need to clear the contents of the copied table and copy another table from the hidden sheet.

要从隐藏的工作表中复制表格,请执行以下操作:

To copy the tables from the hidden sheet I'm using:

source.Cells(leftRow, leftCol).CurrentRegion.Copy target.Range("A1")

问题在于此操作似乎导致selectChanged再次被触发,从而触发了我的ClearContents命令.

The problem is that this action seems to cause selectionChanged to get fired again, which triggers my ClearContents command.

有没有一种方法可以使用此命令而不会触发selectChanged?

Is there a way to use this command without getting selectionChanged fired?

谢谢,李

推荐答案

使用 Application.EnableEvents = False .

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    On Error GoTo Whoa

    Application.EnableEvents = False

    '
    '~~> YOUR CODE
    '

Letscontinue:
    Application.EnableEvents = True
    Exit Sub
Whoa:
    MsgBox Err.Description
    Resume Letscontinue
End Sub

这篇关于VBA Excel使用currentRegion而不使用selectionChanged触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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