Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default Compare and highlight duplicates in two workbooks

Hi, how do I compare column A in Workbook 1 with column A in Workbook 2 and
highlight the entries in Workbook 1 that are found in Workbook 2 ?

Regards
Dylan
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default Compare and highlight duplicates in two workbooks

Hi Dylan

The code below would be one way of doing it or at least give you an
idea where to start.

Option Explicit

Sub FindAndMarkDups()
Dim WkBk1 As Workbook
Dim WkBk2 As Workbook
Dim i As Integer
Dim SearchFor As String
Dim FoundCell

Set WkBk1 = Workbooks("Book1.xls")
Set WkBk2 = Workbooks("Book2.xls")

With WkBk1.Sheets("Sheet1")

..Activate

For i = 1 To [A65535].End(xlUp).Row

SearchFor = .Cells(i, 1).Value

WkBk2.Sheets("Sheet1").Activate

Set FoundCell = [A:A].Find(What:=SearchFor, LookAt:=xlWhole)

If Not FoundCell Is Nothing Then

..Cells(i, 1).Interior.Color = vbRed

End If

Next

..Activate

End With

End Sub

Hope this helps

Steve
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default Compare and highlight duplicates in two workbooks

Thanks Steve, it works perfectly.

Dylan

"Incidental" wrote:

Hi Dylan

The code below would be one way of doing it or at least give you an
idea where to start.

Option Explicit

Sub FindAndMarkDups()
Dim WkBk1 As Workbook
Dim WkBk2 As Workbook
Dim i As Integer
Dim SearchFor As String
Dim FoundCell

Set WkBk1 = Workbooks("Book1.xls")
Set WkBk2 = Workbooks("Book2.xls")

With WkBk1.Sheets("Sheet1")

..Activate

For i = 1 To [A65535].End(xlUp).Row

SearchFor = .Cells(i, 1).Value

WkBk2.Sheets("Sheet1").Activate

Set FoundCell = [A:A].Find(What:=SearchFor, LookAt:=xlWhole)

If Not FoundCell Is Nothing Then

..Cells(i, 1).Interior.Color = vbRed

End If

Next

..Activate

End With

End Sub

Hope this helps

Steve

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 5 columns of text and highlight duplicates based on repeti BarryTheCamper Excel Worksheet Functions 2 January 22nd 10 06:51 PM
Compare data in 2 workbooks and highlight differences in red Sherry Excel Worksheet Functions 4 January 13th 09 12:20 AM
Highlight duplicates SITCFanTN Excel Programming 4 July 11th 08 12:57 PM
Compare two worksheets and Highlight duplicates in each Lisab Excel Programming 10 September 12th 07 05:28 PM
compare two columns within a worksheet, then highlight duplicates Beth Excel Worksheet Functions 1 September 20th 06 03:47 PM


All times are GMT +1. The time now is 07:50 AM.

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

About Us

"It's about Microsoft Excel"