[RESOLVED] [VBA] How to Determine the Last Item in a Collection Object
Basically, title says it all. I would have thought this to be a fairly easy thing to find, but I cannot find the answer to this in any documentation, or on any forums.
This is my first time working with a collection object, but I understand it works similar to an array (although supposedly more optimized according to Chip Pearson who is somewhat of a VBA Guru).
I tried using UBound() to get the last item, but apparently this only works for arrays. Is there a similar function to get the last item in a collection?
To put it into context:
Code:
Sub Test()
Dim Data As Collection
Set Data = New Collection
'Add items to collection
Data.Add "A"
Data.Add "B"
Data.Add "C"
'Remove last item from collection
Data.Remove UBound(Data) 'This line does not work
End Sub
Any help is appreciated.
Re: [VBA] How to Determine the Last Item in a Collection Object
Code:
Data.Remove Data.Count
That should do it.
Re: [VBA] How to Determine the Last Item in a Collection Object
Yes, that works. I knew there had to be a simple solution. :)