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
Community
  • 1
  • 1
  • 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](http://stackoverflow.com/questions/26176185/how-to-delete-rows-based-on-condition-in-vba) 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](http://stackoverflow.com/questions/11169445/error-finding-last-used-cell-in-vba) and then looping only till that row. – Siddharth Rout Oct 03 '14 at 15:47
  • Another Point: Instead of looping, you can also use `.Autofilter` It will be much faster... :) – Siddharth Rout Oct 03 '14 at 15:48

1 Answers1

2

Your IF statement is incorrect. Change to:

If wb1.Sheets("Development Priority List").Cells(i,1).Value < i - 1 Then
Mr. Mascaro
  • 2,693
  • 1
  • 11
  • 18