Thread: Macro If And
View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Otto Moehrbach Otto Moehrbach is offline
external usenet poster
 
Posts: 1,090
Default Macro If And

You're right. I used a For loop that went from top (D5) to bottom and I was
deleting rows as I went. That never works. When you're deleting rows you
have to go from bottom to top. The following corrected macro does that.
Sorry about that. Otto
Sub DeleteRows()
Dim rngHTR As Range
Dim c As Long
Set rngHTR = Range("D5", Range("D" & Rows.Count).End(xlUp))
For c = rngHTR.Count To 1 Step -1
If rngHTR(c) = "Heater" And IsEmpty(rngHTR(c).Offset(, -2).Value)
Then _
rngHTR(c).EntireRow.Delete
Next c
End Sub
"Herve_Rob" wrote
in message ...

Thanks Otto,
With yours, it seems only half of the rows are deleted (1 on 2).

If I have both conditions from rows 5 to 24, the 1st time i run the
macro, only 10 rows (5, 7, 9, 11, 13, 15, 17, 19, 21, 23) are deleted
!?

If i run it again, 5 rows are deleted.....

Thanks


--
Herve_Rob
------------------------------------------------------------------------
Herve_Rob's Profile:
http://www.excelforum.com/member.php...o&userid=35204
View this thread: http://www.excelforum.com/showthread...hreadid=550064