View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Gary''s Student Gary''s Student is offline
external usenet poster
 
Posts: 11,058
Default Delete rows based on an array

Let's say Sheet2 has the data and Sheet1 in column A has the list of rows we
want deleted from Sheet2. For example, in Sheet1 in A1 thru A4 we have:

1
5
7
11

The following macro will remove these rows from Sheet2:

Sub rowkiller()
Dim rkill() As Integer

Sheets("Sheet1").Activate
n = Cells(Rows.Count, 1).End(xlUp).Row
ReDim rkill(1 To n)
For i = 1 To n
rkill(i) = Cells(i, 1).Value
Next

Sheets("Sheet2").Activate
Set rgkill = Cells(rkill(1), 1)
For i = 2 To n
Set rgkill = Union(rgkill, Cells(rkill(i), 1))
Next
rgkill.EntireRow.Delete
End Sub

--
Gary''s Student - gsnu2007f


" wrote:

So.. I have a large worksheet of information for which I need to
delete certain rows based on a list in another worksheet. I need a
delete row function that will look up the value in another worksheet
and delete the row based on that value. Can anyone help?

~Vic