View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Norman Jones Norman Jones is offline
external usenet poster
 
Posts: 5,302
Default Deleting rows that dont...

Hi Dominique,

As Myrna points out, my code retained rows if items from the named list
occur anywhere in the row rather than in column D, as specified. I read your
request insufficiently carefully.

Try, therefore the following revised code:

Sub DelRows3()
Dim uRange As Range
Dim delRange As Range
Dim cell As Range
Dim rCell As Range
Dim blKeep As Boolean

Set uRange = Worksheets("CLSEXCEL").UsedRange
Set delRange = uRange.Cells _
(uRange.Rows.Count + 1, 1).EntireRow
For Each rCell In Intersect(uRange, Columns("D:D"))
blKeep = False
For Each cell In Worksheets("DocList").Range("Forms")
If rCell.Value = cell.Value Then
blKeep = True
Exit For
End If
Next cell
If Not blKeep Then
Set delRange = Union(delRange, rCell.EntireRow)
End If
Next rCell
delRange.Delete
End Sub

Providing I had a range named "Forms" on a sheet named "DocList", the code
worked for me.

---
Regards,
Norman



"Dominique Feteau" wrote in message
...
It didnt work. it ended up deleting everything. is there something else
i need to do? I have my defined name. not sure on why its not working