|
-
Jan 23rd, 2012, 10:19 PM
#1
Thread Starter
Member
[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.
-
Jan 23rd, 2012, 10:37 PM
#2
Member
Re: [VBA] How to Determine the Last Item in a Collection Object
Code:
Data.Remove Data.Count
That should do it.
-
Jan 24th, 2012, 12:52 AM
#3
Thread Starter
Member
Re: [VBA] How to Determine the Last Item in a Collection Object
Yes, that works. I knew there had to be a simple solution.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|