VBA Macro crashes after 32000 rows

后端 未结 3 1641
遇见更好的自我
遇见更好的自我 2020-11-27 08:06

I have a VBA macro that copies rows from one worksheet into another based upon finding values in cells in 3 columns. The macro works, but crashes when it reaches row 32767.

3条回答
  •  时光说笑
    2020-11-27 08:29

    This sounds like an integer Problem

    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.

    But which version are you using? Because:

    Traditionally, VBA programmers have used integers to hold small numbers, because they required less memory. In recent versions, however, VBA converts all integer values to type Long, even if they are declared as type Integer. Therefore, there is no longer a performance advantage to using Integer variables; in fact, Long variables might be slightly faster because VBA does not have to convert them.

    This Information is directly from MSDN

    UPDATE

    Please also read the first comment! I was interpreting the MSDN Information the wrong way!

    Thats MSDN being misleading: VBA does not itself convert Integer to Long. Under the covers the CPU converts integer to long , does the arithmetic and then converts the resulting long back to integer. So VBA integers still cannot hold numbers larger than 32K – Charles Williams

提交回复
热议问题