Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Macro to compare two list


Hi!

I have two worksheets. On the Master list I have a list of cars wit
their Registration numbers and vehicle details, the other has jus
registrations only. I wish to compare the two lists, and remove fro
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 thi
only removes the duplicate registration numbers, not the entire ro
relating to this registration number. Has anyone any idea how I modif
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
Darre

--
DGillha
-----------------------------------------------------------------------
DGillham's Profile: http://www.excelforum.com/member.php...fo&userid=1370
View this thread: http://www.excelforum.com/showthread.php?threadid=56016

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Macro to compare two list


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...


Code
-------------------

' 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).EntireRow.Delete xlShiftUp
' Increment counter to account for deleted row.
iCtr = iCtr + 1
End If
Next iCtr
Next
Application.ScreenUpdating = True
MsgBox "Done!"
End Sub

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


Sincerely,
Leith Ros

--
Leith Ros
-----------------------------------------------------------------------
Leith Ross's Profile: http://www.excelforum.com/member.php...fo&userid=1846
View this thread: http://www.excelforum.com/showthread.php?threadid=56016

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Macro to compare two list


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


--
DGillham
------------------------------------------------------------------------
DGillham's Profile: http://www.excelforum.com/member.php...o&userid=13707
View this thread: http://www.excelforum.com/showthread...hreadid=560165

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Compare my list to an existing list Beep Excel Worksheet Functions 1 December 18th 09 06:41 AM
Macro to compare two list DGillham[_8_] Excel Programming 2 July 14th 06 12:34 PM
Help,, need macro to replace 'space' in list of names with "." (dot), then compare ss jay Excel Programming 0 February 23rd 06 05:33 PM
Compare List mc-iii Excel Worksheet Functions 0 November 13th 04 11:18 AM
Compare List mc-iii Excel Worksheet Functions 3 November 12th 04 11:53 PM


All times are GMT +1. The time now is 08:50 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"