Adding to a New Collection

SBF12345

Well-known Member
Joined
Jul 26, 2014
Messages
614
Greetings,

I am running into some issues while adding a new collection. The collection portion of my script is below:

Code:
Dim col As New CollectionDim col2 As New Collection


col.Add b
col.Add c
col.Add D
col.Add E
col.Add F
col.Add G
col.Add h
col.Add i
col.Add j
col.Add k
col.Add l
col.Add m
col.Add n
col.Add o
col.Add P
col.Add Q
col.Add R
col.Add S
col.Add T
col.Add U
col.Add V
col.Add W
col.Add x
col.Add y
col.Add z
col.Add AA
col.Add AB
col.Add AC
col.Add AD
col.Add AE
col.Add AF
col.Add AG
col.Add AH
col.Add AI
col.Add AJ
col.Add AK
col.Add AL
col.Add AM
col.Add AN
col.Add AO
col.Add AP
col.Add AQ
col.Add AR
col.Add 45
col.Add AT
col.Add AU
col.Add AV
col.Add AW
col.Add AX
col.Add AY
col.Add AZ
col.Add BA
col.Add BB
col.Add BC
col.Add BD
col.Add BE


col2.Add BF

I added a watch to the collections and some of the related variables. While using F8 to step through the code I noticed that the added components were showing as "empty" using the above script.

I also added a watch while adding to the collection in the below format:

Code:
col.Add "BC"
col.Add "BD"
col.Add "BE"

While including the parentheses the collection showed the elements including the parentheses that surrounded them which was conflicting with variables in an unshown portion of the code.

How can I add these strings to the collection without including the parenthesis. BTW the added elements correspond to columns. Also, the 45 is a numerical value for column AS which was in conflict with the statement As.

Thanks!
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
If you are adding to the collection by using a variable that contains a string value, do not use the quotation marks, but the variable must have been initialized to if you want to see its value in the watch window. If you are adding the actual string to the collection, use the quotation marks to indicate to VBA that it is a string and your values will appear in the watch window with quotation marks. In either case, if the value of the variable is a string data type, it will appear with quotation marks which identify it as a string data type.
 
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