Vba to find and highlight matches in excel

Bammo

New Member
Joined
Oct 7, 2013
Messages
1
Hi Everyone,
i have two excel spreadsheets (spreadsheet 1&2). Spreadsheet 1 contains over 2000 rows of names companies and spreadsheet 2 is database dump of various values and names

I am looking for a macro that can find/search each value in spreadsheet 1 and see if there is a match or near match in spreadsheet 2 as well as highlight the match in spreadsheet 1. Alternatively if there is a match in spreadsheet2 it could return locations in a separate column.

i hope this makes sense.
Please any help will be greatly appreciated

Many thanks
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
a possible solution (very slow)
Code:
Sub FindDupSheet1_2()
Dim cell As Range, cella As Range, rng As Range, srng As Range
Set rng = Sheets(2).UsedRange
Set srng = Sheets(1).UsedRange
For Each cell In rng
    For Each cella In srng
    If cella = cell Then
    cella.Interior.ColorIndex = 6
'    cella.AddComment.Text Text:="duplicate value"
    End If
    Next cella
Next cell
End Sub
for faster have a look at http://www.mrexcel.com/forum/excel-...are-two-columns-show-differences-another.html
 
Last edited:
Upvote 0
better solution
Code:
Sub CompareRanges()
LR1 = Worksheets(1).Cells(Rows.Count, "A").End(xlUp).Row
LR2 = Worksheets(2).Cells(Rows.Count, "A").End(xlUp).Row
Set rng1 = Worksheets(1).Range("A1:A" & LR1)
Set rng2 = Worksheets(2).Range("A1:A" & LR1)
    For Each rCell In rng1
        rCell.Interior.ColorIndex = xlNone
        rCell.Validation.Delete
        result = WorksheetFunction.CountIf(rng2, rCell)
        If result > 0 Then rCell.Interior.Color = vbGreen
    Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,262
Messages
6,123,952
Members
449,135
Latest member
jcschafer209

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top