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