Link to home
Start Free TrialLog in
Avatar of Decarn
Decarn

asked on

How to vlookup for duplicates and display the results in a column

Hi Experts,

I have a difficult task which I hope to automate as much as possible. I have attached a sample excel file. The actual file has about 30 columns and 50K+ rows.

I have a master list with columns "IC Number", "ADID" and "Role".

I am given a list with only the "IC Number" and I need to find the "ADID" that are active and disable. The same "IC Number" may have two or more "ADID", hence vlookup will not work. The worksheet tab "desire results" is what I hope to achieve.

How can I do this with the least amount of effort? I am willing to pick up any skills necessary.
Although I am currently using excel 2003, I am open to solutions in 2007. I will push to upgrade if it can dramitcally reduce my work load.

Thanks.
vlookup-ee.xls
Avatar of jawa29
jawa29
Flag of United Kingdom of Great Britain and Northern Ireland image

Hi Decarn

This link looks like something to helop with this.

http://www.cpearson.com/excel/Duplicates.aspx

Jawa29

How about a custom function, based on your data layout.

You enter in B2 and down: =LookUp2($A2,'Master List'!$A$2:$A$12)

In C2 and down: =LookUp2($A2,'Master List'!$A$2:$A$12,TRUE)

Function LookUp2(vItem, rData As Range, Optional bDisabled As Boolean = False) As Variant
 
Dim rFind As Range, s As String, sOut As String

With rData
    Set rFind = .Find(What:=vItem, LookAt:=xlWhole, MatchCase:=False, SearchFormat:=False)
    If Not rFind Is Nothing Then
        s = rFind.Address
        Do
            If bDisabled Then
                If rFind.Offset(, 2) Like "DISABLED*" Then
                    sOut = sOut & ", " & rFind.Offset(, 1)
                End If
            Else
                sOut = sOut & ", " & rFind.Offset(, 1)
            End If
            Set rFind = .Find(What:=vItem, After:=rFind, LookAt:=xlWhole, MatchCase:=False, SearchFormat:=False)
         Loop While rFind.Address <> s
    End If
End With
     
LookUp2 = Mid(sOut, 3)

End Function

Open in new window

Avatar of mawni
mawni

I am sorry, but I can't understand you, can you please give me an example with sheet names and cell index, and I will solve the file and send it back to you
Avatar of Decarn

ASKER

Hi Guys,

Apologies for the late reply. It was the weekend.

Mawani,
I have reattached the excel file.
"Master List" worksheet: This is the list that I already have and it contains the IC Number, ADID and Role. If you notice, there are duplicate IC Numbers but different ADID and Role. i.e. each IC Number can have muplitle ADID and roles.

"List to match" worksheet: This is the list that was given to me to match against the "Master List". It only contains the IC Number and I have to extract all the ADIDs and Roles based on the IC Number.

"Desired Result" worksheet: This is what I want to acheive. Base on the IC Number, I extracted all the ADID and categorised them into Active and Disabled. Active and Disabled is based on the Role in the Master List. As long as there is a word "Disabled" in the Role column, the ADID is deemed as Disabled. Otherwise it is active.

I hope this is clearer and now that the weekend is over, I will respond asap.

Thanks.
vlookup-ee.xls
Did you see my suggestion?
Avatar of Decarn

ASKER

Hi StephenJR,

Apologies, it has been some time since I studied VBA functions in excel. Trying to figure out how to put in the code you have given. Some guidance to kick start will be apprecaited.
Avatar of Decarn

ASKER

Hi  StephenJR,

I got the function to work. Active ADIDs looks good but disabled ADIDs are also showing up as active ADID. Can you also be kind enough to comment your code so that I can learn too.

Thanks.
No problem. Did you see my example?

For column B you need only the first two parameters, e.g.

B2 =LookUp2($A2,'Master List'!$A$2:$A$12)

For column C, you need to specify the third parameter as True (by default it is False so if omitted it will be False)

C2 =LookUp2($A2,'Master List'!$A$2:$A$12,TRUE)

It worked for your sample file - see attachment. If you are trying it on a different dataset perhaps that is causing a problem.
vlookup-ee.xls
Avatar of Decarn

ASKER

Hi Stephen,

I downloaded your file but I still see that in the "Given List to match" worksheet, disabled ADID is also flag as active. In the "desired result" workesheet, everything seems fine but there is no formula.
Lookup2.JPG
ASKER CERTIFIED SOLUTION
Avatar of StephenJR
StephenJR
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Decarn

ASKER

Hi Stephen,

It works. I'm still trying to understand each line of code because the actual spreedsheet has a lot of columns and data. Will appreciate if you could expalin each line of code.

Thanks a lot.
Avatar of Decarn

ASKER

Hi Stephen,

I have another query. Using back the same example, I now have the ADID and will need to distinguish between Active and Inactive. I have attached the sample worksheet - "Given List to match 2" and "Desire result 2".

Do you require me to log in as another question so that I can award more points to you.

Thanks.
vlookup-ee.xls
Avatar of Decarn

ASKER

Thanks Stephen.

I will create a new question for my next question.