Results 1 to 4 of 4

VBA Variant question

This is a discussion on VBA Variant question within the Excel Questions forums, part of the Question Forums category; Does Variant use more memory than Double or Integer or String for ex. ?...

  1. #1
    Board Regular
    Join Date
    Jun 2008
    Posts
    139

    Default VBA Variant question

    Does Variant use more memory than Double or Integer or String for ex. ?

  2. #2
    Board Regular
    Join Date
    Jul 2010
    Location
    New Delhi
    Posts
    348

    Default Re: VBA Variant question

    Yes. Variant data type has a numeric storage size of 16 bytes and can contain data up to the range of a Decimal, or a character storage size of 22 bytes (plus string length), and can store any character text. Try F1 in VBA.
    Hope This Helps !
    Prabby
    --------------------
    WannaB MrExcel MVP
    - tRYING tO fIGURE oUT hOW !

  3. #3
    Board Regular Norie's Avatar
    Join Date
    Apr 2004
    Location
    Stirling
    Posts
    66,050

    Default Re: VBA Variant question

    The short answer is yes - 16 bytes for numbers and 22 bytes + string length for strings.

    Whether it's a good idea to use Variants is another matter/topic/discussion/debate...
    If posting code please use code tags.

  4. #4
    Board Regular
    Join Date
    Feb 2010
    Location
    London, UK
    Posts
    5,002

    Default VBA Variant question

    I believe it does. Excel, by default assumes a variable to be a variant unless it is declared as a specific variable type (e.g. As String, As Double etc). And since a variant is of an unknown variable type, Excel allocates it maximum memory so that it can then be used to store whatever is passed to it.

    This link gives a decent overview of the different variable types and probably a better explanation than me!
    http://www.ozgrid.com/VBA/variables.htm


Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


DMCA.com