1

我有一个Worksheet_Change活动,目前在Sheet Module Level. 问题是我有时希望能够清除这张表。但是,当我清除工作表时,会出现溢出:

Private Sub Worksheet_Change(ByVal Target As Range)
    'This is the line causing the problem because clearing the whole sheet causes the count to be massive
    If Target.Count = 1 Then
        If Target = Range("A4") Then
            If InStr(LCase(Target.Value), "loaded") <> 0 Then
                Range("A5").FormulaArray = "=My_Function(R[-1]C)"
            End If
        End If
    End If
End Sub

我正在努力实现以下目标:

我按下一个按钮并清除工作表(清除现有数组公式数据),然后将公式粘贴到工作表并调用公式。该公式将数据返回到 Excel 缓存,并将包含此公式 (A4) 的单元格更改为表示“已加载”的字符串。当我检测到值“已加载”的单元格更改时,我会在下面的数组公式函数上对Ctrl++Shift执行等效操作,以显示数据。Enter

4

1 回答 1

0

我相信你使用的是xl2007+?

Target.Cells.Count是一个Long值,因此当您选择整个工作表时,.Count它太小而无法容纳结果。

换行

If Target.Count = 1 Then   

If Target.Cells.CountLarge = 1 Then

您可能还想看到这个,因为您正在使用Worksheet_Change

编辑

另外两件事

1)

您也可以替换此行

If Target = Range("A4") Then

If Not Intersect(Target, Range("A4")) Is Nothing Then

2)

这条线

If InStr(LCase(Target.Value), "loaded") <> 0 Then

也可以写成

If InStr(1, Target.Value, "loaded", vbTextCompare) Then
于 2013-02-08T12:30:24.917 回答