Digita
04-20-2009, 12:11 AM
Guys,
I'm doing a little test using the item method. My sample data in column A contains a lot of repeating values. My code below loads unique values to a collection. This part is working OK. My code errors out with a message "Run-time Error '424' Object required". What am I missing?
Dim cUnique As Collection
Dim Rng As Range
Dim Cel As Range
Dim sh As Worksheet
Dim N As Variant, fvalue
Set sh = ThisWorkbook.Sheets("Sheet1")
Set Rng = sh.Range("A1", sh.Range("A1").End(xlDown))
Set cUnique = New Collection
On Error Resume Next
For Each Cel In Rng.Cells
cUnique.Add Cel.Value, CStr(Cel.Value)
Next Cel
On Error GoTo 0
fvalue = cUnique.Item("Lemon")
If Error.Number = 0 Then
msgbox "found"
Else
msgbox "not found"
End If
Thanks & regards
kp
I'm doing a little test using the item method. My sample data in column A contains a lot of repeating values. My code below loads unique values to a collection. This part is working OK. My code errors out with a message "Run-time Error '424' Object required". What am I missing?
Dim cUnique As Collection
Dim Rng As Range
Dim Cel As Range
Dim sh As Worksheet
Dim N As Variant, fvalue
Set sh = ThisWorkbook.Sheets("Sheet1")
Set Rng = sh.Range("A1", sh.Range("A1").End(xlDown))
Set cUnique = New Collection
On Error Resume Next
For Each Cel In Rng.Cells
cUnique.Add Cel.Value, CStr(Cel.Value)
Next Cel
On Error GoTo 0
fvalue = cUnique.Item("Lemon")
If Error.Number = 0 Then
msgbox "found"
Else
msgbox "not found"
End If
Thanks & regards
kp