title: How to fix Compile Error: Sub or function not defined in VBA?
body: <p>This is a code that goes through the cells in column B in <a href="https://i.stack.imgur.com/zo9aF.png" rel="nofollow noreferrer">sheet2</a>. If it finds a value that is not a date in column B, then it copies it, pastes it another sheet called 'errors' and then deletes that row from Sheet2. Whenever I try to run this, however, I get a 'Compile Error: Sub or function not defined'. I saw some other posts on this, but nothing mentioned there seemed to work for me. </p>
  
  <pre><code>Sub removeerrors()
  Dim i As Range
  Dim x As Double
  x = Worksheet("Errors").CountA("A1:A100")
  
      For Each i In Worksheet("Sheet2").Range(Range("A2"), Range("A2").End(xlDown))
          If IsDate(i.Offset(0, 1)) = False Then
              Range(i, i.End(xlToRight)).Copy
              Worksheet("Errors").Range("A1").Offset(x, 0).Paste
              Range(i).EntireRow.Delete
          End If
      Next i
  End Sub
  </code></pre>