PDA

View Full Version : Advice on comparing excel workbooks



jonaslin
10-23-2019, 07:22 AM
Hi,

Im seeking advice on where to start to try to automaticly compare two columns in two workbooks and have an output in a third column.

For an example

compare workbook1 column S compare with workbook2 column I (not sorted and the rows not match) it need to take the first row in workbook1 S column and search the entire workbook2 column I to find a match when match found check the column H in workbook1 is there a value, skip and go to next row, is the cell empty then fill it out from workbook2 column I

All advice appriciated

Thanks
Jonas

SamT
10-23-2019, 08:19 AM
is the cell empty then fill it out from workbook2 column I:dunno

大灰狼1976
10-23-2019, 10:10 PM
Hi Jonas!
Welcome to vbax forum.
Not sure if the understanding is wrong.



Sub test()
Dim Wb1 As Workbook, Wb2 As Workbook, rng As Range, i&
Dim Sh1 As Worksheet, sh2 As Worksheet
Set Wb1 = Workbooks("Book1"): Set Wb2 = Workbooks("Book2")
Set Sh1 = Wb1.Sheets(1): Set sh2 = Wb2.Sheets(1)
For i = 1 To Sh1.Cells(Rows.Count, "s").End(3).Row
Set rng = sh2.Columns("i").Find(Sh1.Cells(i, "s"), lookat:=xlWhole)
If Not rng Is Nothing Then
If Sh1.Cells(i, "h") = "" Then Sh1.Cells(i, "h") = rng
End If
Next i
End Sub


--Okami