Target.count导致溢出错误

Dav*_*eyD 4 excel vba overflow excel-vba

我有Worksheet_SelectionChange功能.在第一行中,我想条件是如果选择了多于1个单元格,则退出.我写:

    If Target.Cells.Count > 1 Then Exit Sub
Run Code Online (Sandbox Code Playgroud)

但是,当我选择整个工作表时,我收到一条错误消息:"运行时错误6 - 溢出"

好像Target.Count无法处理如此庞大的数字?

我该怎么做才能解决这个问题?

Jea*_*ett 14

替换CountCountLarge.

文档:http://msdn.microsoft.com/en-us/library/office/ff196838(v = office.15).aspx

CountLarge属性在功能上与Count属性相同,只是Count如果指定的范围超过2,147,483,647个单元格(一个小于2048列),则属性将生成溢出错误.CountLarge但是,该属性可以处理工作表的最大大小范围,即17,179,869,184个单元格.