title: Why should I use the DIM statement in VBA or Excel?
body: <p>So there is a <a href="https://stackoverflow.com/questions/1033507/what-does-dim-stand-for-in-visual-basic-and-basic">question on <em>what</em> <code>DIM</code> is</a>, but I can't find why I want to use it.</p>
  
  <p>As far as I can tell, I see no difference between these three sets of code:</p>
  
  <pre><code>'Example 1
  myVal = 2
  
  'Example 2
  DIM myVal as Integer
  myVal = 2
  
  'Example 3
  DIM myVal = 2
  </code></pre>
  
  <p>If I omit <code>DIM</code> the code still runs, and after 2 or 3 nested loops I see no difference in the output when they are omitted. Having come from Python, I like to keep my code clean*.</p>
  
  <p><strong>So why should I need to declare variables with <code>DIM</code>?</strong> Apart from stylistic concerns, is there a technical reason to use <code>DIM</code>?</p>
  
  <p><sup>* also I'm lazy and out of the habit of declaring variables.</sup></p>