title: Find and delete Rows where cell value is "#N/A"
body: <p>I have an excel document that I use to analyze data sets each data asset I bring in has varying amounts of data.  I have tried to write a macro that I assign to a button that can identify delete rows based on the value of a  cell. It does not work.  What am I doing wrong?</p>
  
  <pre><code>Sub Button2_Click()
  [vb]
  'This will find how many rows there are
   With ActiveSheet
      lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
      MsgBox lastRow
   End With
  
   Sub sbDelete_Rows_Based_On_Criteria()
       Dim lRow As Long
       Dim iCntr As Long
       lRow = lastRow
       For iCntr = lRow To 1 Step -1
           'Replaces XX with the variable you want to delete
           If Cells(iCntr, 1) = "#N/A" Then
               Rows(iCntr).Delete
           End If
       Next
   End Sub
   [/vb]
  End Sub
  </code></pre>