View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Mike H Mike H is offline
external usenet poster
 
Posts: 11,501
Default Delete Rows for given conditions.

Hi,

This assumes your codes that you want to delete are in column A of sheet 2.

Right click the sheet tab with your data in, View code and paste this in and
run it. N

Sub delete_Me()
Dim DelFalg As Boolean
Dim copyrange As Range, CheckRange As Range
LastrowA = Sheets("Sheet2").Cells(Cells.Rows.Count, "A").End(xlUp).Row
Set CheckRange = Sheets("Sheet2").Range("A1:A" & LastrowA)
lastrow = Cells(Cells.Rows.Count, "E").End(xlUp).Row
Set MyRange = Range("E1:E" & lastrow)
For Each c In MyRange
delflag = False
For Each r In CheckRange
If c = r Then
delflag = True
Exit For
End If
Next
If delflag Then
If copyrange Is Nothing Then
Set copyrange = c.EntireRow
Else
Set copyrange = Union(copyrange, c.EntireRow)
End If
End If
Next
If Not copyrange Is Nothing Then
copyrange.Delete
End If
End Sub


Mike

"fpd833" wrote:

I'm looking for some coding help. I have a large worksheet of data that
varies in length (well over 4k rows) and I'm looking to delete rows based on
a "code" entered in col E. The "code" in col E is text based and varies in
length.

I have a list of 85 or so codes that I want to delete from the data sample
without having to perform this manually. I've found code to delete rows based
on a cell value, but cannot figure out how to make it loop through all of the
codes I have to remove.

Is this even possible? Any help would be greatly appreciated. Thanks!