D
Derek Gadd
Hi,
I'm trying to create a collection from a given range of cells. The
code seems to run but the collection I try to create (in this case
called "MainCategory") has no data in it. Can anybody help?
Thanks,
Derek
Public MainCategory As New Collection
Dim AllCells As Range
Sub Test()
<code>
Set AllCells = Range(Range("top_label").Offset(1, 0),
Rang("top_label").End(xlDown))
' Create a new collection
Set MainCategory = CreateCollection(AllCells)
End Sub
Function CreateCollection(AllCells As Range) As Collection
Dim Cell
'Prevents errors from trying to have duplicate entries
On Error Resume Next
For Each Cell In AllCells
CreateCollection.Add Cell.Value, CStr(Cell.Value)
Next Cell
On Error GoTo 0
End Function
I'm trying to create a collection from a given range of cells. The
code seems to run but the collection I try to create (in this case
called "MainCategory") has no data in it. Can anybody help?
Thanks,
Derek
Public MainCategory As New Collection
Dim AllCells As Range
Sub Test()
<code>
Set AllCells = Range(Range("top_label").Offset(1, 0),
Rang("top_label").End(xlDown))
' Create a new collection
Set MainCategory = CreateCollection(AllCells)
End Sub
Function CreateCollection(AllCells As Range) As Collection
Dim Cell
'Prevents errors from trying to have duplicate entries
On Error Resume Next
For Each Cell In AllCells
CreateCollection.Add Cell.Value, CStr(Cell.Value)
Next Cell
On Error GoTo 0
End Function