VBA Variant question

Pjam

Board Regular
Joined
Jun 4, 2008
Messages
139
Does Variant use more memory than Double or Integer or String for ex. ?
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
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.
 
Upvote 0
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...:)
 
Upvote 0
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!
<html>http://www.ozgrid.com/VBA/variables.htm</html>
 
Upvote 0

Forum statistics

Threads
1,214,588
Messages
6,120,409
Members
448,959
Latest member
camelliaCase

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top