Finding Matching Data in Separate Workbooks

AussieJac

Board Regular
Joined
Jul 7, 2005
Messages
57
Hi all,

I have the following macro that finds a contract number listed in Column C in one sheet to where it appears in the following 10 sheets (in column B) then it returns the message "Found in Data Base".

What I want is this to work with two separate workbooks - one containing a list of contract numbers to be found in the second workbook. And instead of returning "Found in Data Base" when a match is found, I would like it to copy the Name of the contract corresponding the the contract number as a check.

In the macro below I have opened up the second workbook but I am unsure how to tell the macro to switch between the two workbooks.

Code:
Sub FindMatch()
' Open Data Base file to facilitate matching process.
' Check for matching data

Dim currentfile As String
Dim WS As Worksheet
Dim R As Range

    Application.ScreenUpdating = False
    Application.DisplayAlerts = False

    Workbooks.Open Filename:= _
        "G:\Registration\Data List amended for DOD.xls"
    MsgBox ("Opening DataBase")
    
    Windows("Claimed Matching Data.xls").Activate
    Sheets("M - Matching Data").Select
    [L3].Select
    While ActiveCell.Offset(0, -9) <> Empty
       
        For Each WS In Sheets(Array("List A", "List B", "List C", "List D", "List E", "List F"))
            Set R = WS.Range("b2:b3000").Find(ActiveCell.Offset(0, -9))

            If Not R Is Nothing Then
                ActiveCell.Offset(0, 1).Value = "Found in Data Base"
                  
        Exit For
            End If
        Next
        ActiveCell.Offset(1).Select
        
    Wend
End Sub

Any help would be appreciated.
Jac :confused:
 
This should do it:
Code:
Sub test2()
' Open Data Base file to facilitate matching process.
' Check for matching data

Dim currentfile As String
Dim WS As Worksheet
Dim R As Range
Dim Myvalue As String
Dim Myrange As Range
Dim Tcell As Range

Application.ScreenUpdating = False
Application.DisplayAlerts = False

'    Workbooks.Open Filename:= _
'        "G:\Registration\Data List amended for DOD.xls"
'    MsgBox ("Opening DataBase")
 Workbooks.Open Filename:=ThisWorkbook.Path & "\Data List amended for DOD.xls"
 ThisWorkbook.Sheets("M - Matching Data").Activate
  
For Each Tcell In ActiveSheet.Range("C3:C" & ActiveSheet.Range("C65536").End(xlUp).Row)

    Set Myrange = Tcell.Offset(0, 1)
    Myvalue = Tcell.Value
    
        For Each WS In Workbooks("Data List amended for DOD.xls").Sheets
           Select Case WS.Name
              Case "List A", "List B", "List C", "List D", "List E", "List F"
                 With WS.Range("b2:b3000")
        
                     Set R = .Find(Myvalue, LookIn:=xlValues)
                     If Not R Is Nothing Then
                          Myrange.Offset(0, 9).Value = "Found in Data Base"
                          Myrange.Offset(0, 10).Value = R.Offset(0, 3).Value
                     End If
                 End With
           End Select
        Next WS
        Next Tcell
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub

BTW: The error was due to a 1 in the place of an L in the following line:
Code:
("C65536").End(xlUp).Row)

I told you I don't sleep enough. I don't know how I managed that.
:LOL:

Mac
 
Upvote 0

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"
I've been mucking around with it some more and thanks to your great tutoring I have now got it copying from one spreadsheet to the other but I am having trouble trying to highlight the line in the database with a color index !
I've been playing with the following line and inserting it after "Myrange.Offset(0, 9).Value = "Found in Data Base""

Select.Row.Interior.ColorIndex = 3


I've tried various combinations but no joy!


Code:
 With WS.Range("b2:b3000")
        
Set R = .Find(Myvalue, LookIn:=xlValues, lookat:=xlWhole)
If Not R Is Nothing Then
                     
Myrange.Offset(0, 9).Value = "Found in Data Base"
                          

                          
Myrange.Offset(0, 10).Value = R.Value 'copies contract number from database
Myrange.Offset(0, 11).Value = R.Offset(0, 2).Value 'copies Date of Birth from database
Myrange.Offset(0, 12).Value = R.Offset(0, 3).Value 'copies Name from database
R.Offset(0, 15).Value = Myrange.Offset(0, 4).Value'copies Claim No TO database
'R.Offset(0, 16).Value = Myrange.Offset(0, 5).Value'copies Amount Paid TO database
 
Upvote 0
Hi Jac! If I understand correctly, you want to highlight the Row in which the match is found? Try this:

Code:
Myrange.Offset(0, 9).Value = "Found in Data Base" 
R.EntireRow.Interior.ColorIndex=3
 
Upvote 0
Hi Mac
Thanks again. It works perfectly (as always)

Hope you had a great weekend.
and thanks again for your help.

Jac
 
Upvote 0

Forum statistics

Threads
1,214,922
Messages
6,122,281
Members
449,075
Latest member
staticfluids

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