Compare Sheet and Columns

doku

New Member
Joined
May 20, 2007
Messages
22
I am not sure if its a duplicate post.
I tried searching the forum, but couldn't relate it to the scenario I needed.
Book1
ABCD
1Sheet1
2NameAge
3a10
4b20
5c30
6d40
7e50
8
9Sheet2
10NameAge
11b20
12c30
13d40
14
15Sheet3
16NameAge
17anotfound
18bmatched
19cmatched
20ddidntmatch
21enotfound
Sheet1


I have three sheet. named Sheet1, Sheet2 and Sheet3.
Sheet1 being the master sheet. What I want to achieve is:
I want to search for Name in sheet1 with the list of names in Sheet2,
If the name is found, then compare the Age in Sheet1 and Sheet2. If the age matches make an entry in Sheet3 "matched" else "didnt match".
If the name itself is not found on sheet2 , make an entry saying not found.
I am not sure what would be the best approach to solve the problem(formula/VB)...
Hope I am clear with my query...
Can you all please help ?
 
Yes.... I got that....
The only confusion that I have now is....
If I want to compare a column index 5 in sheet1 and column index 8 in sheet2 and the result to be palced in column index 5 in sheet3.
Is that possible ?

Of course. Just change the Column Index in the formula accordingly. and then move the cell wherever you wish.
 
Upvote 0

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Yes.... I got that....
The only confusion that I have now is....
If I want to compare a column index 5 in sheet1 and column index 8 in sheet2 and the result to be palced in column index 5 in sheet3.
Is that possible ?
Code:
Sub test()
Dim a, b, i as Long, w(), e
With Sheets("sheet1")
    a = .range("e1", .Range("e" & rows.count).end(xlUp)).resize(,2).value
end with
With createobject("scripting.dictionary")
    .comparemode = vbtextcompare
    For i = 2 To ubound(a, 1)
        .item(a(i, 1)) = Array(a(i, 2), i)
    Next
    with Sheets("sheet2")
        b = .range("h1", .range("h" & rows.count).end(xlUp)).resize(, 2).value
    end with
    For i = 2 to UBound(b, 1)
        If .exists(b(i, 1)) then
            w = .item(b(i, 1))
            a(w(1), 2) = IIf(w(0) <> b(i, 2),"not ","") & "matched
            .remove b(i, 1)
        End if
    Next
    if .count > 0 then
        for each e in .items
            a(e(1), 2) = "not found"
        next
    end if
End with
Sheets("sheet3").cells(1, "e").resize(ubound(a,1), 2).value = a
End Sub
 
Upvote 0
I checked with both the approach.....
Both works fine for me.....
I am trying few more things on that....
will get back if I have any confusion...
 
Upvote 0

Forum statistics

Threads
1,216,124
Messages
6,128,979
Members
449,480
Latest member
yesitisasport

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