I am trying to execute a For Loop that goes through a range looking for cells that are blank, or contain an #N/A. The reason I have to do this is that I am wanting to do a CountA to find the number of cells that contain the data I want to count, but unless I do a ClearContents on the blank cells, the CountA counts them (and of course the #N/A cells as well). That one is a mystery to me, but here is the For Loop I am using to accomplish the ClearContents function:
The problem is that the For Loop is blowing up when it encounters the first #N/A, and giving me a Type Mismatch error. What am I doing wrong here?
Code:
For lngRow = 3 To Cells(Rows.Count, 1).End(xlUp).Row - 2
If (Cells(lngRow, lngCol + 2) = "" Or Cells(lngRow, lngCol + 2) = "#N/A") Then
Cells(lngRow, lngCol + 2).ClearContents
End If
Next lngRow
The problem is that the For Loop is blowing up when it encounters the first #N/A, and giving me a Type Mismatch error. What am I doing wrong here?