+ Reply to Thread
Results 1 to 3 of 3

Macro to compare two list

  1. #1
    Registered User
    Join Date
    08-27-2004
    Posts
    40

    Macro to compare two list

    Hi!

    I have two worksheets. On the Master list I have a list of cars with their Registration numbers and vehicle details, the other has just registrations only. I wish to compare the two lists, and remove from the Master list
    any vehicle that is on the registration list only.

    I've been able to use the Macro from the Microsoft website, but this only removes the duplicate registration numbers, not the entire row relating to this registration number. Has anyone any idea how I modify this macro to delete the row, not just the cell?

    Sub DelDups_TwoLists()
    Dim iListCount As Integer
    Dim iCtr As Integer

    ' Turn off screen updating to speed up macro.
    Application.ScreenUpdating = True


    ' Get count of records to search through (list that will be deleted).
    iListCount = Sheets("Master").Range("A1:A2500").Rows.Count

    ' Loop through the "master" list.
    For Each x In Sheets("Sheet2").Range("A1:A2500")
    ' Loop through all records in the second list.
    For iCtr = 1 To iListCount
    ' Do comparison of next record.
    ' To specify a different column, change 1 to the column number.
    If x.Value = Sheets("Master").Cells(iCtr, 1).Value Then
    ' If match is true then delete row.
    Sheets("Master").Cells(iCtr, 1).Delete xlShiftUp
    ' Increment counter to account for deleted row.
    iCtr = iCtr + 1
    End If
    Next iCtr
    Next
    Application.ScreenUpdating = True
    MsgBox "Done!"
    End Sub

    Thanks in advance
    Darren

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259
    Hello Darren,

    To delete the entire row this line needs to be changed from:
    Sheets("Master").Cells(iCtr, 1).Delete xlShiftUpHere is the revised
    to:
    Sheets("Master").Cells(iCtr, 1).EntireRow.Delete xlShiftUpcode

    Here is the revised code...

    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

  3. #3
    Registered User
    Join Date
    08-27-2004
    Posts
    40
    Thanks Leith

    How difficult is it to rather than delete the row, to cut and paste it onto another workbook? Sorry to trouble you with this, but it would be a great help!

    Darren

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1