Finding multiple results

asjmoron

Board Regular
Joined
Apr 26, 2016
Messages
98
Office Version
  1. 2016
Platform
  1. Windows
Hi All,

I am having a real hard time trying to explain what am actually trying to do as result so I have tried to demo it below.

I need to change this

RefResult
a1231
b1232
c1233
a1232
a1231
b1231

<colgroup><col width="64" span="2" style="width:48pt"> </colgroup><tbody>
</tbody>


into this

a1231, 2 ,1
b1232, 1
c1233

<colgroup><col width="64" span="2" style="width:48pt"> </colgroup><tbody>
</tbody>


And I dont know the best way to do it (or if it is actually possible).

There are around 15,000 records with about 30% of them being duplicates of the ref (a maximum of 11 duplicates) but the reult can be any number. Any advise would be very welcomed.
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
This is a common request, concatenating results. Not easily possible with simple formulas.
May be possible with Power Query, certainly possible with VBA, though I'm no expert on either.
 
Upvote 0
Hi
May be
Code:
Sub test()
    Dim a As Variant, lr, i, k, itm
    a = Range("a2:a" & Cells(Rows.Count, 1).End(xlUp).Row).Resize(, 2)
    With CreateObject("scripting.dictionary")
        For i = 1 To UBound(a)
            If Not .exists(a(i, 1)) Then
                .Add a(i, 1), a(i, 2)
            Else
                .Item(a(i, 1)) = .Item(a(i, 1)) & ", " & a(i, 2)
            End If
        Next
        Cells(2, 3).Resize(.Count, 2) = Application.Transpose(Array(.Keys, .Items))
    End With
End Sub

If your data starts at A2,B2
 
Last edited:
Upvote 0
Hi
May be
Code:
Sub test()
    Dim a As Variant, lr, i, k, itm
    a = Range("a2:a" & Cells(Rows.Count, 1).End(xlUp).Row).Resize(, 2)
    With CreateObject("scripting.dictionary")
        For i = 1 To UBound(a)
            If Not .exists(a(i, 1)) Then
                .Add a(i, 1), a(i, 2)
            Else
                .Item(a(i, 1)) = .Item(a(i, 1)) & ", " & a(i, 2)
            End If
        Next
        Cells(2, 3).Resize(.Count, 2) = Application.Transpose(Array(.Keys, .Items))
    End With
End Sub

If your data starts at A2,B2

This almost works. The ref is colum A but the results are in C. I tried making (what I thought would be) the ammendment but it didnt work. I am loking to have the output in Column J if that helps?
 
Upvote 0
Ok
just

Code:
 Cells(2, [COLOR=#ff0000]10[/COLOR]).Resize(.Count, 2) = Application.Transpose(Array(.Keys, .Items))
 
Upvote 0
we did it! By Jove I think we did it!

I had to make another small adjustment (a(i, 3)) but its working now.

Thanks!
 
Upvote 0
You are well come
Thanks for the feedback
Be happy
 
Upvote 0

Forum statistics

Threads
1,213,546
Messages
6,114,256
Members
448,557
Latest member
richa mishra

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