title: Excel VBA object variable type mismatch
body: <p>I am trying to determine the column number of a header in an Excel spreadsheet using the following VBA code:</p>
  
  <pre><code>Dim aCell As Range
  Set aCell = Sheet1.Rows(1).Find(What:="ContractDescription", LookIn:=xlValues, _
   LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
   MatchCase:=False, SearchFormat:=False)
  </code></pre>
  
  <p>Then the following line of code gives an error:</p>
  
  <pre><code>MsgBox (aCell.Column)
  </code></pre>
  
  <p>It gives the run-time error 91: "Object variable or With block variable not set".</p>
  
  <p>According to posts that I have read on the internet, this error occurs when you are trying to assign a value of one type to a variable that has been declared as a different type.</p>
  
  <p>However, I am trying to understand why I am getting this error here since <code>aCell</code> is a range object and I am simply taking <code>aCell.Column</code>, but when I do <code>Range("A1").Column</code> I do get the valid <code>1</code> printed on the screen.</p>
  
  <p>So what may be causing the problem here?</p>