Long vs. Integer

Once upon a time I read that Excel does not use the Integer data type internally. If you use the Integer data type in your code, Excel will convert it to a Long, so you might as well just use Long. It still produces an overflow error if you get outside the Integer bounds, I’ve noticed.

I haven’t used Integer in years because of this, but now I don’t recall who said it and when. It was certainly in a newsgroup post, but I couldn’t google it very easy. Does anyone know if this is true?

6 Comments

  1. Dick says:

    That’s cool. It doesn’t say why, but Long is consistently faster than Integer.

  2. Ivan F Moala says:

    Thats because Integers are actually converted in the underlying VB Engine. The compilied code is 32 bit, so using Longs skips the under the hood conversion.

  3. ross says:

    InsaneExcel is a cool site, very good kid, check it out, i’ve know about it for time, excel error!

  4. Harald Staff says:

    Hi Dick

    I’m the Who. I post it from time to time so I can’t help with a distinct When.

    http://groups.google.com/groups?selm=OH7ThgyyDHA.604%40tk2msftngp13.phx.gbl&output=gplain

    Best wishes Harald

  5. John Mocambique says:

    The update page link that Harald refers to is:

    http://msdn.microsoft.com/en-us/library/aa164754(office.10).aspx

    Which is titled (in case it moves again):

    Microsoft Office XP Developer
    The Integer, Long, and Byte Data Types

Posting code or formulas in your comment? Use <code> tags!

  • <code lang="vb">Block of code goes here</code>
  • <code lang="vb" inline="true">Inline code goes here</code>
  • <code>Formula goes here</code>

Leave a Reply

Here's how to update your reports of company and nearly any web data: