PDA

View Full Version : Do Loop help



rjplante
02-16-2010, 12:20 PM
I have a table of data (table 1) and I want it to check against another table (table 2) and then remove the lines from table 1 that are in table 2. I have a do loop that checks the row numbers in table 1 against those in table 2. When it finds a match in table 1, it should delete that row and then continue through the list to check for any additional matches. Table 1 has 250 rows and table 2 has 30 rows. There may be intervening spaces between rows of data that need to be removed.

I think I need to have a nested loop and I am not sure how to get this done. My code for the initial loop is listed below.

---------------------------------

Sheets("Wish List").Select

' Remove cells from wish list for orders placed
Range("A4").Select
Counter = 0
myNum = 1
Do Until Counter = 250
myNum = myNum - 1
Counter = Counter + 1

If ActiveCell.Value = Range("BP2").Value Then Exit Do
Selection.Offset(1, 0).Select

Loop

Selection.Offset(0, 1).Select
Range(Selection, Selection.Offset(0, 7)).Select

Application.Run "DEL_WL_BLOCK"

Bob Phillips
02-16-2010, 01:15 PM
Untested



With Sheets("Wish List")

LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

For i = LastRow To 4 Step -1

If Not IsError(Application.Match(.Cells(i, "A"), Columns("BP"), 0)) Then

.Rows(i).Delete
End If
Next i
End With

Application.Run "DEL_WL_BLOCK"