VBA Collections into Collections

JST013

Board Regular
Joined
Mar 11, 2015
Messages
74
I'm trying to make a collection out of a list of items in cells. Each cell may or may not have a few items separated by ","'s...

I've got that part down...At least I think... but then I get to line 9, my DontDupe collection is empty... I expected it to possibly just hold the last added collection .... but it has nothing...not sure whats I'm missing, but everything seems to be fine up to that point.

Please find the code I am using below.


thank you in advance!

Code:
Dim DontDupe As New Collection
Dim splitdies As New Collection


1    Set dies = ws.Range("Standards[Die Number]")
    On Error Resume Next
2       For Each die In dies
3            drow = die.Row
4           dcol = die.Column
5            Set splitdies = Splitter(ws.Cells(drow, dcol))
            
       
6            For Each guy In splitdies
7                DontDupe.Add guy.Value, CStr(guy.Value)
8            Next guy
9        Next die

''I will then get rid of any duplicates and put this collection into a combo box...

'-----------------------------------------------------------------------------

here is my splitting function

Code:
Function Splitter(rg As Range) As Collection
Dim x As New Collection
Dim hey As Variant


hey = Split(rg.Value, ",")
For j = 0 To UBound(hey, 1)
    x.Add hey(j), CStr(hey(j))
Next


Set Splitter = x
End Function
 

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.
NVM!

Figured it out...

my line 7 needed to be

Code:
7                DontDupe.Add guy, CStr(guy.value)
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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