Consulting

Results 1 to 3 of 3

Thread: Advice on comparing excel workbooks

  1. #1
    VBAX Newbie
    Joined
    Oct 2019
    Posts
    1
    Location

    Advice on comparing excel workbooks

    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

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    is the cell empty then fill it out from workbook2 column I
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  3. #3
    VBAX Mentor 大灰狼1976's Avatar
    Joined
    Dec 2018
    Location
    SuZhou China
    Posts
    479
    Location
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •