VBA - Compare Two Lists on seperate sheets

blista99

New Member
Joined
Aug 28, 2015
Messages
10
Hello everyone! :)
Thank you for all the great solutions I could copy/paste from here to use for my own projects. Unfortunately I do now have a rather simple task, which I can figure out to work. I've tried several attempts, but did not get a satisfying result.
The situation is the following:
I have two big and monthly changing exports of data with 12+ collumns each and 500-1000 rows in two different sheets of the same workbook. But the only thing to compare them is one collumn each; an id-nummer. Like this:

NameIDDateTimeTaskTrackingNrDefinition
sfzdtznd882532603.04.201111:32#250002585laksdjfla
dghdfufgb885336905.09.201208:35#850008563wtgjdhgj
fdfgjdzuj882354705.12.201309:07#670006797asdwdtrzs
rhdjhgfu687243221.01.201503:59#870008721qdfdasg
.....................

<tbody>
</tbody>
The second table has as much data as the first one but different values and collumn-names. Except for the ID and the date. The data is sorted by date but similarities are rather luck than wanted. The collumn description is not at the same position, meaning the ID/Date for expl. is in G/K [table 1] and once in B/H [table 2].

What I would like to have, is a VBA code which compares each ID of table 1 (Import_1) with the ID's of table two (Import_2) [as mentioned; two sheets in the same workbook] and outputs a value at the end of each row in table 1, where the ID matches with one of table two. And if not found to output a value one collumn more to the right. See below:
NameIDDateTimeTaskTrackingNrDefinition"Found in Table 2""Not Found"
sfzdtznd882532603.04.201111:32#250002585laksdjfla1
dghdfufgb885336905.09.201208:35#850008563wtgjdhgj1
fdfgjdzuj882354705.12.201309:07#670006797asdwdtrzs1
rhdjhgfu687243221.01.201503:59#870008721qdfdasg1
.....................

<tbody>
</tbody>


Thanks for your kind help.
Greets blista99
 
Last edited:

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
See if this will work for you.
Code:
Sub IsItThere()
Dim sh1 As Worksheet, sh2 As Worksheet, lr As Long, c As Range, fn As Range
Set sh1 = Sheets(1) 'Edit sheet name
Set sh2 = Sheets(2) 'Edit sheet name
lr = sh1.Cells(Rows.Count, "G").End(xlUp).Row
    For Each c In Range("G2:G" & lr)
        Set fn = sh2.Range("B:B").Find(c.Value, , xlValues, xlWhole)
            If Not fn Is Nothing Then
                sh1.Cells(c.Row, Columns.Count).End(xlToLeft)(1, 2) = 1
            Else
                sh1.Cells(c.Row, Columns.Count).End(xlToLeft)(1, 3) = 1
            End If
    Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,833
Messages
6,121,858
Members
449,051
Latest member
excelquestion515

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