I'm getting the following error when I try to run a routine in an Excel macro:
"Excel Run time error 1004 Application-defined or Object-defined error"
The routine is listed below. I am attempting to delete all rows/records within the used range except those that have "California" as the value in column "A". Columns "A" through "E" are the only columns in the used range and each cell within that range may or may not contain data (i.e. there are some cells or entire rows within the range that are blank or may contain garbage data).
Dim lastrow As Long, I As Long
'get last row
lastrow = Range("F" & ActiveSheet.Rows.Count).End(xlUp).Row
Do While I <= lastrow
If Cells(I, 1) <> "California" Then <------ GETTING THE ERROR ON THIS LINE
'decrement value of lastrow since we deleted a row
lastrow = lastrow - 1
'increment counter to go to next row
I = I + 1