1

I am trying to compare the value of a cell (always a number) to the iteration variable in a for loop but for some reason vba says this is an invalid call or argument. I am new to vba so any help would be greatly appreciated.

For i = 2 To wb1.Sheets("Development Priority List").Rows.Count

If wb1.Sheets("Development Priority List").Cells("A" & i).Value < i - 1 Then
    wb1.Sheets("Development Priority List").Range("A" & i, "Z" & i).Delete
End If

Next i
2
  • Besides what @jbarker2160 mentioned below. There is one more thing. You have to delete the rows in reverse loop else you will miss the rows. Se THIS And one more important point. You are using .Rows.Count That means it will loop though all the rows in the worksheet. Why would you want to do that. I would recommend finding the lastrow using THIS and then looping only till that row. Commented Oct 3, 2014 at 15:47
  • Another Point: Instead of looping, you can also use .Autofilter It will be much faster... :) Commented Oct 3, 2014 at 15:48

1 Answer 1

2

Your IF statement is incorrect. Change to:

If wb1.Sheets("Development Priority List").Cells(i,1).Value < i - 1 Then
Sign up to request clarification or add additional context in comments.

2 Comments

+ 1 You beat me to it :)
Or replace .Cells with .Range

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.