View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Mark Bigelow Mark Bigelow is offline
external usenet poster
 
Posts: 55
Default macro to clear rows

I've run into this before. The reason it's missing items is because
when it deletes the row, the row numbers shift up and your counter,
rowIndex, misses one. If you want to delete, use a Do/While loop. If
clearing is okay, change .delete to .clear.

Sub delete()

rwIndex = 1
Do while rwIndex <= 200
With ActiveSheet.Cells(rwIndex, 1)
If ((.Value) = 0) Then
Rows(rwIndex).delete
Else
rwIndex = rwIndex + 1
End If
End With
Loop

End Sub

Sub delete()

For rwIndex = 1 To 200
With ActiveSheet.Cells(rwIndex, 1)
If ((.Value) = 0) Then
Rows(rwIndex).clear
End If
End With
Next rwIndex

End Sub

Let me know if you have questions.

Mark

---
Mark Bigelow
mjbigelow at hotmail dot com
http://hm.imperialoiltx.com

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!