kingofaces
Board Regular
- Joined
- Aug 23, 2010
- Messages
- 68
Using collections is something I picked upon just recently, so I'm having a little trouble understanding why the current function returns a #Name error. Basically what I'm trying to do is add the y1 and y2 variables into a collection called ygroup. I'm then using a For Each loop to do a calculation for each of the y variables within y group. This is an example I have been tinkering with to try and understand how I could use collections in some of my larger projects, so any insight would go a long way. I am a bit of a beginner when it comes to collections and arrays, so maybe there is a much simpler solution if this isn't the most feasible method?
I get the feeling I've just misunderstood how to properly enter the data into a collection after Googling various examples which didn't seem to explain the process very well for me.
Code:
Function test(x, y1, y2) As Long
Dim ygroup As New Collection
Dim y As Long
test1 As Long
With ygroup
.Add Item:=y1
.Add Item:=y2
End With
For Each y In ygroup
Do
test1 = (x + y)
test = test + test1
Next y
End Function
I get the feeling I've just misunderstood how to properly enter the data into a collection after Googling various examples which didn't seem to explain the process very well for me.