Compare two columns in one workbook with two columns in another work book and return values

Vbapadawan

New Member
Joined
Jul 5, 2015
Messages
13
I have a problem and in desperate need of help.
I am trying to create an analysis tool to compare the information in two workbooks and return data to the source workbook.

For example;
I have two work books, one current and one history that I want to compare and return the status and status date from the history WB to the current WB
In each workbook I have a column with a depot code, one with a consignment number and one with the consignment line number.
I need to compare where all three of these columns match, the columns in each workbook are not in the same order.
The History workbook can have multiple sheets that need to be searched

History.xls
Depot Code Consign No Consign line status stat date
BNE A123 0001 C 01/01/2016
OAK A223 0001 O 02/05/2015
BNE A123 0005 W 02/02/2016
DRN B123 0002 C 01/01/2014
BNE Z2356 0001 O 01/01/2016

NTX DO.xls
Depot Code Consign No Consign line status stat date History status History Date
BNE A123 0001 C 01/01/2016
OAK A223 0001 O 02/05/2015
BNE A125 0005 W 02/02/2016
DRN B123 0002 C 01/01/2014
BNE Z2356 0001 O 01/01/2016

I have tried to adapt some code I have that compares one criteria, but can't seem to get it to compare two.

Code:
Sub Analysis_due_out()

    Dim rngFound As Range
    Dim strFirst As String
    Dim strID As String
    Dim strDay As String
    
'Open Source Workbook from Objective
Workbooks.Open Filename:=("https://drms-amberley/id:L6507647")
'activate target workbook/sheet
Windows("NTX DO.xls").Activate
'Sheets("SOH").Visible = True
Sheets("SOH").Activate

For Each c In Range("AM2:AM" & Range("a65536").End(xlUp).Row)

Application.StatusBar = "Processing: " & ActiveSheet.Name & " Row: " & c.Row


    strID = Range("H" & c.Row).Value
    strDay = Range("I" & c.Row).Value
    
    
 Windows("History.xls").Activate 'open IDR to search
Worksheets("Report Sheet 1").Activate
    Set rngFound = Columns("K").Find(strID, Cells(Rows.Count, "K"), xlValues, xlWhole)
    If Not rngFound Is Nothing Then
        strFirst = rngFound.Address
        Do
            If LCase(Cells(rngFound.Row, "L").Text) = LCase(strDay) Then  'ActiveCell.Row <> 1
                'Found a match
                 
  Stat = Cells(rngFound.Row, "I").Value
  Dte = Cells(rngFound.Row, "U").Value
  
 GoTo 10
Else: End If        
10
'activate target workbook/sheet
Windows("NTX DO.xls").Activate
c.Value = Dte
c.Offset(0, 1).Value = Stat


            Set rngFound = Columns("K").Find(strID, rngFound, xlValues, xlWhole)
        Loop While rngFound.Address <> strFirst
    End If

  
Dte = ""
Stat = ""
Next c
  Set rngFound = Nothing
End Sub
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.

Forum statistics

Threads
1,215,025
Messages
6,122,734
Members
449,094
Latest member
dsharae57

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