Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

Excel Run time error 1004 Application-defined or Object-defined error

Avatar of dbfromnewjersey
dbfromnewjerseyFlag for United States of America asked on
Microsoft OfficeMicrosoft Excel
3 Comments1 Solution3270 ViewsLast Modified:
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
Rows(I).Delete
'decrement value of lastrow since we deleted a row
lastrow = lastrow - 1
Else
'increment counter to go to next row
I = I + 1
End If
Loop