title: VBA: Check if a Variable Exists
body: <p>I have the following function to check for the existence of a variable:</p>
  
  <pre><code>Private Function DoesVariableExist(Optional valuePassed As Variant) As Boolean
      If Not IsMissing(valuePassed) And Not IsEmpty(valuePassed) Then
          DoesVariableExist = True
      End If
  End Function
  </code></pre>
  
  <p>The idea being that if the variable doesn't exist, I can run different code than if it does exist.</p>
  
  <p>The code works fine as long as I remove the <code>Option Explicit</code> line from the module. With that line in there, I get a compiler error, "Variable not defined," because, of course, that's what I'm checking for. This is a small module with only a handful of procedures, so I could probably get away with not requiring variable declaration, but that's not good coding practice. So, what's the alternative?</p>