{"id":12164,"date":"2012-10-14T12:59:06","date_gmt":"2012-10-14T12:59:06","guid":{"rendered":"http:\/\/www.learnexcelmacro.com\/?p=2544"},"modified":"2022-08-12T11:13:28","modified_gmt":"2022-08-12T11:13:28","slug":"declaring-multiple-variables-with-one-dim-statement","status":"publish","type":"post","link":"https:\/\/vmlogger.com\/excel\/2012\/10\/declaring-multiple-variables-with-one-dim-statement\/","title":{"rendered":"Important : Declaring multiple Variables with one Dim Statement"},"content":{"rendered":"
Hello friends, In VBA one can declare more than one variables with a single Dim statement as written below:<\/p>\n Dim VAR1, VAR2, VAR3 As Integer<\/font><\/p>\n From the above way of declaration, usually we think that all the above 3 variables are declared as “Integer” Type. But this is NOT correct. Only the last variable VAR3 is declared as Integer and rest 2 variables are declared as Variant Type. (Note: Default type of variables in VBA is Variant). The above declaration is functionally equivalent to the following: Still if you want to declare all the three variables of Integer type with one Dim Statement then As Type modifier<\/i><\/font> must be used for each variable declared with the Dim statement as below: Dim VAR1 As Integer, VAR2 As Integer, VAR3 As Integer<\/font> Coming to the question on top, with the explanation given above it is clear that both the declarations are NOT the same<\/strong><\/font> but the below two ways of declarations are exactly same: Hello friends, As you know in VBA variables are declared using Dim Statement. You have also learnt about how to declare a variable in VBA in the previous articles. You have also learnt about Implicit and explicit option variables. Here is a question: In below image there are two ways of declaring three […]<\/p>\n","protected":false},"author":45,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[5204],"tags":[],"class_list":["post-12164","post","type-post","status-publish","format-standard","hentry","category-vba-programming"],"yoast_head":"\n
\n
\nAs you know in VBA variables are declared using Dim Statement<\/strong><\/font><\/a>. You have also learnt about how to declare a variable in VBA in the previous articles. You have also learnt about Implicit and explicit option variables.<\/strong><\/font><\/a>
\n
\nHere is a question:<\/strong><\/font> In below image there are two ways of declaring three variables VAR1, VAR2 and VAR3 as an integer type. Is there any difference between two ways of declarations?<\/strong><\/font>
\n
\nAnswer:<\/strong><\/font> Yes there is a difference between both the declaration. To know what is the difference read the explanation \ud83d\ude42
\n
\n
\n<\/p>\nExplanation:<\/h2>\n
\n
\nDim VAR1 As Variant
\nDim VAR2 As Variant
\nDim VAR3 As Integer
\n <\/font><\/p>\n
\n <\/p>\n
\n <\/p>\n
\n
\n<\/p>\n<\/span>","protected":false},"excerpt":{"rendered":"