I'm starting to get the basics of VBA and I've wrote a macro which does the stuff I want (might not be the most elegant way but it works).
One of the things it does is write an excel formula to certain cells in column 8
"=VLOOKUP(RC[-6],TotalsPerClient!C9:C12,4,FALSE)"
This VLOOKUP is going to return some #N/A values and that's fine for me. Afterwards I like to go through the column and remove the errors. I first tried the following:
For i = 1 To LastRow
If ws4.Cells(i, 8).Value = CVErr(xlErrNA) Then
ws4.Cells(i, 8).ClearContents
End If
Next i
However, I get a type mismatch. I understand now that since there is not a formula in every cell some cells do not give an error and hence a type mismatch. I've then used the following:
If IsError(ws4.Cells(i, 8).Value) Then
ws4.Cells(i, 8).ClearContents
End If
Which works and does the trick.
For educational purposes; is there a way to use the Cell.Value = CVErr(xlErrNA) instead of my own solution? Using the CVErr(xlErrNA) seems a bit more specific and would narrow down the scope of what I'm deleting.