Number of instance

I want following result in excel in column B

Sr    AA    BBB
1      a      1,2,3,6,7   <-------------Wherever "a" is reflected
2      a      1,2,3,6,7
3      a      1,2,3,6,7
4      b      4,5
5      b      4,5
6      a      1,2,3,6,7
7      a      1,2,3,6,7
8      c      8,9,10
9      c      8,9,10
10      c      8,9,10
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
You may use the following User Defined Function to get the desired output.
Function CustomConcatenate(ByVal Rng As Range, ByVal LookupStr As String) As String
Dim x
Dim Str As String
Dim i As Long
x = Rng.Value
For i = 1 To UBound(x, 1)
    If LCase(x(i, 2)) = LCase(LookupStr) Then
        If Str = "" Then
            Str = x(i, 1)
            Str = Str & ", " & x(i, 1)
        End If
    End If
Next i
CustomConcatenate = Str
End Function

Open in new window

Then use this function as below...

In C2

Open in new window

and then copy it down.
Refer to the attached for details.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
TEJAS NIMBALKARAuthor Commented:
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
You're welcome Tejas!
Please take a minute to accept the answer to mark your question as Solved.
How many rows and how many distinct values are you processing?
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
The chosen answer resolved the original question.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.