I have an excel spread sheet with 2 columns, with the last row being 287983
. In column A there's numbers, if a cell doesn't have a number NaN
is placed there. In, column B there's dates. I'm trying to use the following macro to remove all rows where cells in column A have NaN
:
Sub Rowdel()
Dim i As Long
For i = Cells(Rows.Count, 1).End(xlUp).Row To 1 Step -1
If Cells(i, 1) = "NaN" Then Cells(i, 1).EntireRow.Delete
Next i
End Sub
However, when I run the above code, the NaN
cells are still there. Can anyone suggest why the code isn't working?
Worksheets("Sheet1").Cells(Rows.Count, 1)
? – deusxmach1naDebug.Print Cells(i, 1)
inside of you loop and verifying that what you get is indeed 'NaN'. – RocketDonkeysheetx.Cells(i,...
– K_BTrim(Lcase(Cells(i,1))) = "nan"
. Or useStrComp()
. Sometimes string comparisons can be flakey. – Dave Lewis