出现溢出错误,当我使用函数“ActiveSheet.UsedRange.Rows.Count”在 excel VBA 中查找计数时
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21556506/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
getting overflow error, when I used the function "ActiveSheet.UsedRange.Rows.Count" to find the count in excel VBA
提问by user3271436
I am getting an overflow error, when I tried to use the function
当我尝试使用该函数时,出现溢出错误
ActiveSheet.UsedRange.Rows.Count
ActiveSheet.UsedRange.Rows.Count
in VBA Excel
在 VBA Excel 中
回答by user2140261
I am going on assumption you have something like the following:
我将假设您有以下内容:
Dim x as Integer
x = ActiveSheet.UsedRange.Rows.Count
To fix simply change it to:
要修复只需将其更改为:
Dim x as Long
x = ActiveSheet.UsedRange.Rows.Count
Or
或者
Dim x&
x = ActiveSheet.UsedRange.Rows.Count
The ampersand (&) type-declaration character represents a Long
与号 (&) 类型声明字符表示 Long
The Integer and Long data types can both hold positive or negative values. The difference between them is their size: Integer variables can hold values between -32,768 and 32,767, while Long variables can range from -2,147,483,648 to 2,147,483,647
Integer 和 Long 数据类型都可以包含正值或负值。它们之间的区别在于它们的大小:整数变量可以保存 -32,768 到 32,767 之间的值,而 Long 变量的范围可以从 -2,147,483,648 到 2,147,483,647
Because Excel worksheets can have more then 32,767 rows, you cannot ALWAYSfit the number of rows into an integer, and must use a Long.
因为 Excel 工作表可以有超过 32,767 行,所以您不能总是将行数放入一个整数中,并且必须使用 Long。
回答by Fewster
Have you defined your variable as an integer rather than a long or float? If there are more than 32256 or something rows it's too big to be an integer.
您是否将变量定义为整数而不是长整数或浮点数?如果有超过 32256 行或其他行,则它太大而不能成为整数。