{"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,
\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\"Multiple
\n<\/p>\n

Explanation:<\/h2>\n

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:
\n 
\nDim VAR1 As Variant
\nDim VAR2 As Variant
\nDim VAR3 As Integer
\n <\/font><\/p>\n

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:
\n <\/p>\n

Dim VAR1 As Integer, VAR2 As Integer, VAR3 As Integer<\/font>
\n <\/p>\n

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:
\n 
\n\"Multiple<\/p>\n<\/span>","protected":false},"excerpt":{"rendered":"

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":"\nImportant : Declaring multiple Variables with one Dim Statement - Let's excel in Excel<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/vmlogger.com\/excel\/2012\/10\/declaring-multiple-variables-with-one-dim-statement\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Important : Declaring multiple Variables with one Dim Statement\" \/>\n<meta property=\"og:description\" content=\"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 […]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/vmlogger.com\/excel\/2012\/10\/declaring-multiple-variables-with-one-dim-statement\/\" \/>\n<meta property=\"og:site_name\" content=\"Let's excel in Excel\" \/>\n<meta property=\"article:publisher\" content=\"http:\/\/www.facebook.com\/vmlogger\" \/>\n<meta property=\"article:author\" content=\"http:\/\/www.facebook.com\/vmlogger\" \/>\n<meta property=\"article:published_time\" content=\"2012-10-14T12:59:06+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-08-12T11:13:28+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2012\/10\/Variable-Declaration.png\" \/>\n<meta name=\"author\" content=\"Vishwamitra Mishra\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/www.twitter.com\/learnexcelmacro\" \/>\n<meta name=\"twitter:site\" content=\"@learnexcelmacro\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Vishwamitra Mishra\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/vmlogger.com\/excel\/2012\/10\/declaring-multiple-variables-with-one-dim-statement\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/2012\/10\/declaring-multiple-variables-with-one-dim-statement\/\"},\"author\":{\"name\":\"Vishwamitra Mishra\",\"@id\":\"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/7500a107b0b2d35a8492acf0d11fc8e5\"},\"headline\":\"Important : Declaring multiple Variables with one Dim Statement\",\"datePublished\":\"2012-10-14T12:59:06+00:00\",\"dateModified\":\"2022-08-12T11:13:28+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/2012\/10\/declaring-multiple-variables-with-one-dim-statement\/\"},\"wordCount\":277,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/7500a107b0b2d35a8492acf0d11fc8e5\"},\"image\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/2012\/10\/declaring-multiple-variables-with-one-dim-statement\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2012\/10\/Variable-Declaration.png\",\"articleSection\":[\"VBA Programming\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/vmlogger.com\/excel\/2012\/10\/declaring-multiple-variables-with-one-dim-statement\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/vmlogger.com\/excel\/2012\/10\/declaring-multiple-variables-with-one-dim-statement\/\",\"url\":\"https:\/\/vmlogger.com\/excel\/2012\/10\/declaring-multiple-variables-with-one-dim-statement\/\",\"name\":\"Important : Declaring multiple Variables with one Dim Statement - Let's excel in Excel\",\"isPartOf\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/2012\/10\/declaring-multiple-variables-with-one-dim-statement\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/2012\/10\/declaring-multiple-variables-with-one-dim-statement\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2012\/10\/Variable-Declaration.png\",\"datePublished\":\"2012-10-14T12:59:06+00:00\",\"dateModified\":\"2022-08-12T11:13:28+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/2012\/10\/declaring-multiple-variables-with-one-dim-statement\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/vmlogger.com\/excel\/2012\/10\/declaring-multiple-variables-with-one-dim-statement\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/vmlogger.com\/excel\/2012\/10\/declaring-multiple-variables-with-one-dim-statement\/#primaryimage\",\"url\":\"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2012\/10\/Variable-Declaration.png\",\"contentUrl\":\"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2012\/10\/Variable-Declaration.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/vmlogger.com\/excel\/2012\/10\/declaring-multiple-variables-with-one-dim-statement\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/vmlogger.com\/excel\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"VBA Programming\",\"item\":\"https:\/\/vmlogger.com\/excel\/vba-programming\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Important : Declaring multiple Variables with one Dim Statement\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/vmlogger.com\/excel\/#website\",\"url\":\"https:\/\/vmlogger.com\/excel\/\",\"name\":\"Let's excel in Excel\",\"description\":\"Let's share knowledge\",\"publisher\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/7500a107b0b2d35a8492acf0d11fc8e5\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/vmlogger.com\/excel\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/7500a107b0b2d35a8492acf0d11fc8e5\",\"name\":\"Vishwamitra Mishra\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2022\/07\/avataaars-1.png\",\"contentUrl\":\"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2022\/07\/avataaars-1.png\",\"width\":528,\"height\":560,\"caption\":\"Vishwamitra Mishra\"},\"logo\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/image\/\"},\"description\":\"My name is Vishwamitra Mishra. Friends Call me Vishwa. I hold a Bachelor\u2019s Degree in Computer Science from D.A.V.V. Indore & currently working as a Technical Lead having over 7 years of experience.\",\"sameAs\":[\"http:\/\/www.learnexcelmacro.com\",\"http:\/\/www.facebook.com\/vmlogger\",\"https:\/\/x.com\/https:\/\/www.twitter.com\/learnexcelmacro\",\"https:\/\/www.youtube.com\/c\/VMLogger\"],\"url\":\"https:\/\/vmlogger.com\/excel\/author\/vishwamitra\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Important : Declaring multiple Variables with one Dim Statement - Let's excel in Excel","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/vmlogger.com\/excel\/2012\/10\/declaring-multiple-variables-with-one-dim-statement\/","og_locale":"en_US","og_type":"article","og_title":"Important : Declaring multiple Variables with one Dim Statement","og_description":"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 […]","og_url":"https:\/\/vmlogger.com\/excel\/2012\/10\/declaring-multiple-variables-with-one-dim-statement\/","og_site_name":"Let's excel in Excel","article_publisher":"http:\/\/www.facebook.com\/vmlogger","article_author":"http:\/\/www.facebook.com\/vmlogger","article_published_time":"2012-10-14T12:59:06+00:00","article_modified_time":"2022-08-12T11:13:28+00:00","og_image":[{"url":"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2012\/10\/Variable-Declaration.png"}],"author":"Vishwamitra Mishra","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/www.twitter.com\/learnexcelmacro","twitter_site":"@learnexcelmacro","twitter_misc":{"Written by":"Vishwamitra Mishra","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/vmlogger.com\/excel\/2012\/10\/declaring-multiple-variables-with-one-dim-statement\/#article","isPartOf":{"@id":"https:\/\/vmlogger.com\/excel\/2012\/10\/declaring-multiple-variables-with-one-dim-statement\/"},"author":{"name":"Vishwamitra Mishra","@id":"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/7500a107b0b2d35a8492acf0d11fc8e5"},"headline":"Important : Declaring multiple Variables with one Dim Statement","datePublished":"2012-10-14T12:59:06+00:00","dateModified":"2022-08-12T11:13:28+00:00","mainEntityOfPage":{"@id":"https:\/\/vmlogger.com\/excel\/2012\/10\/declaring-multiple-variables-with-one-dim-statement\/"},"wordCount":277,"commentCount":0,"publisher":{"@id":"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/7500a107b0b2d35a8492acf0d11fc8e5"},"image":{"@id":"https:\/\/vmlogger.com\/excel\/2012\/10\/declaring-multiple-variables-with-one-dim-statement\/#primaryimage"},"thumbnailUrl":"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2012\/10\/Variable-Declaration.png","articleSection":["VBA Programming"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/vmlogger.com\/excel\/2012\/10\/declaring-multiple-variables-with-one-dim-statement\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/vmlogger.com\/excel\/2012\/10\/declaring-multiple-variables-with-one-dim-statement\/","url":"https:\/\/vmlogger.com\/excel\/2012\/10\/declaring-multiple-variables-with-one-dim-statement\/","name":"Important : Declaring multiple Variables with one Dim Statement - Let's excel in Excel","isPartOf":{"@id":"https:\/\/vmlogger.com\/excel\/#website"},"primaryImageOfPage":{"@id":"https:\/\/vmlogger.com\/excel\/2012\/10\/declaring-multiple-variables-with-one-dim-statement\/#primaryimage"},"image":{"@id":"https:\/\/vmlogger.com\/excel\/2012\/10\/declaring-multiple-variables-with-one-dim-statement\/#primaryimage"},"thumbnailUrl":"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2012\/10\/Variable-Declaration.png","datePublished":"2012-10-14T12:59:06+00:00","dateModified":"2022-08-12T11:13:28+00:00","breadcrumb":{"@id":"https:\/\/vmlogger.com\/excel\/2012\/10\/declaring-multiple-variables-with-one-dim-statement\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/vmlogger.com\/excel\/2012\/10\/declaring-multiple-variables-with-one-dim-statement\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/vmlogger.com\/excel\/2012\/10\/declaring-multiple-variables-with-one-dim-statement\/#primaryimage","url":"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2012\/10\/Variable-Declaration.png","contentUrl":"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2012\/10\/Variable-Declaration.png"},{"@type":"BreadcrumbList","@id":"https:\/\/vmlogger.com\/excel\/2012\/10\/declaring-multiple-variables-with-one-dim-statement\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/vmlogger.com\/excel\/"},{"@type":"ListItem","position":2,"name":"VBA Programming","item":"https:\/\/vmlogger.com\/excel\/vba-programming\/"},{"@type":"ListItem","position":3,"name":"Important : Declaring multiple Variables with one Dim Statement"}]},{"@type":"WebSite","@id":"https:\/\/vmlogger.com\/excel\/#website","url":"https:\/\/vmlogger.com\/excel\/","name":"Let's excel in Excel","description":"Let's share knowledge","publisher":{"@id":"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/7500a107b0b2d35a8492acf0d11fc8e5"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/vmlogger.com\/excel\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/7500a107b0b2d35a8492acf0d11fc8e5","name":"Vishwamitra Mishra","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/image\/","url":"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2022\/07\/avataaars-1.png","contentUrl":"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2022\/07\/avataaars-1.png","width":528,"height":560,"caption":"Vishwamitra Mishra"},"logo":{"@id":"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/image\/"},"description":"My name is Vishwamitra Mishra. Friends Call me Vishwa. I hold a Bachelor\u2019s Degree in Computer Science from D.A.V.V. Indore & currently working as a Technical Lead having over 7 years of experience.","sameAs":["http:\/\/www.learnexcelmacro.com","http:\/\/www.facebook.com\/vmlogger","https:\/\/x.com\/https:\/\/www.twitter.com\/learnexcelmacro","https:\/\/www.youtube.com\/c\/VMLogger"],"url":"https:\/\/vmlogger.com\/excel\/author\/vishwamitra\/"}]}},"_links":{"self":[{"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/posts\/12164"}],"collection":[{"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/users\/45"}],"replies":[{"embeddable":true,"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/comments?post=12164"}],"version-history":[{"count":0,"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/posts\/12164\/revisions"}],"wp:attachment":[{"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/media?parent=12164"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/categories?post=12164"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/tags?post=12164"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}