Consulting

Results 1 to 2 of 2

Thread: Do Loop help

  1. #1
    VBAX Newbie
    Joined
    Feb 2010
    Posts
    4
    Location

    Do Loop help

    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.

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

    [VBA]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"[/VBA]
    Thanks a ton! - The learning curve is steep and I feel like I am wearing well greased shoes.

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Untested

    [vba]

    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"
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •