View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Janis Janis is offline
external usenet poster
 
Posts: 360
Default delete row syntax


I tried it and it worked!
"Jim Thomlinson" wrote:

Give this a try... (untested but it should be close)

Sub deleteColoredRows()
Dim rng As Range
Dim rngToSearch As range
Dim rngToDelete as Range
Const LtGray = 15
Const DkGray = 16

With Activesheet
Set rngToSearch = .Range(.Range("A1"), .Cells(rows.count, "A").end(xlUp))
end with
for each rng in rngToSearch
if rng.Interior.ColorIndex = LtGray Or _
rng.Interior.ColorIndex = DkGray then
if rngtodelete is nothing then
set rngToDelete = rng
else
set rngtodelete = union(rngToDelete, rng)
end if
end if
next rng
if not rngtodelete is nothing then rngtoDelete.entirerow.delete

End Sub

--
HTH...

Jim Thomlinson


"Janis" wrote:

Sub deleteColoredRows()

Const LtGray = 15
Const DkGray = 16
Range("A1").EntireRow.Select
Do While ActiveCell.Value < ""
ActiveCell.Offset(1, 0).EntireRow.Select


Selection.Interior.ColorIndex = LtGray Or DkGray
EntireRow.Delete

Loop

End Sub

The loop works, the only thing wrong is the delete line.
If the row is either shade of gray I want it to delete.
what is the correct syntax for the delete line?
many thanks,