If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Deleting Rows when using for each cell in loop

Hi All,

I have the following code that checks each cell in range for a certain condition. If it meets the criteria then the entire row is deleted. The problem I'm having is that once a row is deleted the "Next Cell" potion of the code jumps down a row rather than dealing with the next cell in the range. Is there a quick fix to amend this issue?

[vba]Sub remove_WE_Dates_Outside_Period()

Dim Range1 As Range

Set Range1 = Range(ActiveCell, ActiveCell.End(xlDown))
For Each cell In Range1
If DateValue(cell) < DateSerial(Year(Date), Month(Date) - 1, 1) Then

A normal For i = ... Next loop increments i by 1 every iteration of the loop. By using Step, you can increment by some other value. In this code I am using step -1 which increments by -1, or decrements by 1, which has the effect of working from the bottom upwards.