title: VBA check length of cell value in a range
body: <p>I have codes that populate cells in column A (A7:A446) of a main sheet. These values are listed in a different sheet (Sheet3) and the user double-clicks on a code they want to populate the active cell back on the main sheet. These codes have descriptions (Column E, E7:E446)  that go with them and the codes themselves are supposed to be 21 characters long. Currently, the description column (Column E) has a IF(ISNA(VLOOKUP...)) formula to pull the account descriptions associated with the account code being double-clicked in Sheet3. I want to write in VBA, a sub that checks if the codes in column A are 21 characters long. If the account codes are not 21 characters long, I want the description, and only the description, to be "N/A" to indicate that the code is invalid. In addition, if the code in column A does not equal any of the account codes listed in Sheet3, I would like the same action, the description in column E to be "N/A, and the only the description. </p>
  
  <p>I'm aware I can probably do this with a formula or function inside the description column itself but in an attempt to better familiarize myself with VBA, I'd like to do it this way. I've tried to write a sub to do this but it has not been working. I think I have set some of the variable to incorrect datatypes but I'm not entirely sure. Any help/suggestions would be greatly appreciated. </p>
  
  <pre><code>  Sub acctCodeVarification()
  
  acctCode = Sheet2.Range("C7:C446").Value
  acctDesc = Sheet2.Range("E7:E446").Text
  
  For Each c In Range("C7:C446").Cells
      If Len(c) &lt;&gt; 21 Then
      c.acctDesc = "N/A"
      If c &lt;&gt; Sheet3.Range("A1:A20681").Value Then
      c.acctDesc = "N/A"
  
      End If
      End If
  Next c
  
  End Sub
  </code></pre>