VBA整数溢出为70,000 [英] VBA Integer Overflow at 70,000
问题描述
我有一个工作表,其中包含70,000行数据和一个简单的宏,用于计算总行数:
I have a worksheet with 70,000 rows of data and a simple macro that counts the total number of rows:
Dim LastRow as Integer
LastRow = SourceSheet.Cells.Find(what:="*", searchdirection:=xlPrevious, searchorder:=xlByRows).Row
MsgBox (LastRow)
这将返回一个溢出错误.将LastRow更改为Long会返回70,000的正确值.
This returns an overflow error. Changing LastRow to Long returns the correct value of 70,000.
根据 Microsoft的网站,VBA整数应能够保存-2,147,483,648之间的值和2,147,483,647.我的输出在此范围内,为什么会失败?
According to Microsoft's website, a VBA integer should be able to hold values between -2,147,483,648 and 2,147,483,647. My output is well within this range, so why would it fail?
谢谢!
推荐答案
您正在寻找的网站是针对Visual Studio(.NET)的.
The website you are looking at is for Visual Studio (.NET) .
VBA整数是32,768.您需要使用很长的时间.
VBA Integer is 32,768. You need to use a long.
VBA Long变量保存从-2,147,483,648到2,147,483,647的整数,并使用4个字节(32位)的内存.
A VBA Long variable holds whole numbers from -2,147,483,648 to 2,147,483,647 and uses 4 bytes (32 bits) of memory.
Dim lLastRow as Long
这篇关于VBA整数溢出为70,000的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!