Help with Emptying a Collection
How about just setting the collection to a new collection:
If CheckEmpty.Count 20 Then
Set CheckEmpty = New Collection
End If
or if you really, really want to remove the items from the collection:
Option Explicit
Sub CollectionEmptyTry()
Dim CheckEmpty As Collection
Dim iCtr As Long
Set CheckEmpty = New Collection
Dim Obj As String
Obj = Range("P17").Value
For iCtr = 1 To 25
If Cells(1, 1) < "" Then
CheckEmpty.Add Obj
End If
Next iCtr
If CheckEmpty.Count 20 Then
For iCtr = CheckEmpty.Count To 1 Step -1
CheckEmpty.Remove iCtr
Next iCtr
End If
MsgBox CheckEmpty.Count
End Sub
pacer1 wrote:
Hello,
I am trying to empty a collection and am receiving an error message:
Run-time error '424':
Object Required
Sub CollectionEmptyTry()
Dim Obj As String
Obj = Range("P17").Value
If Cells(1, 1) < "" Then
CheckEmpty.Add Obj
End If
If CheckEmpty.Count 20Then
Set CheckEmpty = Empty
End If
MsgBox CheckEmpty.Count
End Sub
Any help with this error would be greatly appreciated.
Also any suggestions on different ways to empty a collection?
Is there any way to remove more than 1 item with the Remove Method?
CheckEmpty.Remove (1 to CheckEmpty.count) ???
Thanks,
pace
--
Dave Peterson
|