Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 260
Default Retrieving a Collection Item

hey guys

I am trying to retrieve the 2nd item in the collection.
The code below adds every item in the specified range to
the collection without any problems, but when it gets to
the last line in the code "FindVal = X.Item(2)" , it says
empty. The 2nd item in the list is "dog" So I want the
msgbox to pop up the value "dog".

Private Sub CommandButton1_Click()
Dim Rng As Range
Dim CL As Object
Dim TestNum As Long
Dim FindVal
Dim X As New Collection

TestNum = 0
Set Rng = Worksheets("Sheet1").Range("A1:A10")
For Each CL In Rng
TestNum = TestNum + 1
If CL.Value < "" Then
X.Add Item:=Inst, key:=CStr(TestNum)
Else
End If
Next

FindVal = X.Item(2)
MsgBox FindVal


Thanks
Todd Huttenstine
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Retrieving a Collection Item

Todd,

Add Option Explicit at the top of your code module, run it again, and you
will find exactly what is wrong.

--

HTH

RP

"Todd Huttenstine" wrote in message
...
hey guys

I am trying to retrieve the 2nd item in the collection.
The code below adds every item in the specified range to
the collection without any problems, but when it gets to
the last line in the code "FindVal = X.Item(2)" , it says
empty. The 2nd item in the list is "dog" So I want the
msgbox to pop up the value "dog".

Private Sub CommandButton1_Click()
Dim Rng As Range
Dim CL As Object
Dim TestNum As Long
Dim FindVal
Dim X As New Collection

TestNum = 0
Set Rng = Worksheets("Sheet1").Range("A1:A10")
For Each CL In Rng
TestNum = TestNum + 1
If CL.Value < "" Then
X.Add Item:=Inst, key:=CStr(TestNum)
Else
End If
Next

FindVal = X.Item(2)
MsgBox FindVal


Thanks
Todd Huttenstine



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 260
Default Retrieving a Collection Item

lol amazing. I cant believe I overlooked that. Thanks!

Todd


-----Original Message-----
Todd,

Add Option Explicit at the top of your code module, run

it again, and you
will find exactly what is wrong.

--

HTH

RP

"Todd Huttenstine"

wrote in message
...
hey guys

I am trying to retrieve the 2nd item in the collection.
The code below adds every item in the specified range to
the collection without any problems, but when it gets to
the last line in the code "FindVal = X.Item(2)" , it

says
empty. The 2nd item in the list is "dog" So I want the
msgbox to pop up the value "dog".

Private Sub CommandButton1_Click()
Dim Rng As Range
Dim CL As Object
Dim TestNum As Long
Dim FindVal
Dim X As New Collection

TestNum = 0
Set Rng = Worksheets("Sheet1").Range("A1:A10")
For Each CL In Rng
TestNum = TestNum + 1
If CL.Value < "" Then
X.Add Item:=Inst, key:=CStr(TestNum)
Else
End If
Next

FindVal = X.Item(2)
MsgBox FindVal


Thanks
Todd Huttenstine



.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
To find rate of each item from item.xls and to copy price.xls pol Excel Discussion (Misc queries) 7 July 16th 09 12:49 AM
Item numbers result in item description in next field in Excel Cheryl MM Excel Worksheet Functions 1 February 20th 07 03:51 PM
Retrieving an Item from a List that Meets Multiple Criteria hgopp99 Excel Worksheet Functions 0 January 21st 06 03:10 PM
Add Unique item to Collection Dick Kusleika[_3_] Excel Programming 8 January 21st 04 08:59 PM
Removing an Item From a Collection Dan Gesshel Excel Programming 4 November 1st 03 01:12 PM


All times are GMT +1. The time now is 03:02 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"