+ Reply to Thread
Results 1 to 3 of 3

Can't change values of items in a collection

  1. #1
    Registered User
    Join Date
    01-14-2013
    Location
    USA
    MS-Off Ver
    Office 2010, Excel
    Posts
    10

    Can't change values of items in a collection

    When I try to change the value of items in a collection, I get the runtime error '424' Object Required.

    Windows 7 Home Premium
    Microsoft Office Professional 2010
    Excel version: 14.0.7116.5000 (32-bit)

    Here's the test code (not sure how to make it appear like code)

    Public Sub test()

    Dim txtdata As New Collection

    txtdata.Add "text 1"
    txtdata.Add "text 2"
    txtdata.Add "text 3"

    txtdata(3) = txtdata(1) & txtdata(2)

    End Sub


    When I run this sample code, I get the runtime error '424' Object Required on the line reassigning txtdata(3). When I look at the collection in the watch window, it shows that each member of the collection is a Variant/String type.

    I have tried using "Set txtdata(3) = txtdata(1) & txtdata(2)", and get the same error.

    Any thoughts are greatly appreciated.
    Thanks

  2. #2
    Forum Expert
    Join Date
    08-02-2013
    Location
    Québec
    MS-Off Ver
    Excel 2003, 2007, 2013
    Posts
    1,412

    Re: Can't change values of items in a collection

    Hi,

    I believe you can not modify element in a collection, you have to remove the element and reassign it :

    Please Login or Register  to view this content.
    I usually use custom class to do this. Here a simple example :

    In a custom class (here called Classe1)

    Please Login or Register  to view this content.
    And in a standard module :
    Please Login or Register  to view this content.
    GC Excel

    If this post helps, then click the star icon (*) in the bottom left-hand corner of my post to Add reputation.

  3. #3
    Registered User
    Join Date
    01-14-2013
    Location
    USA
    MS-Off Ver
    Office 2010, Excel
    Posts
    10

    Re: Can't change values of items in a collection

    Thanks GC, this solution works well.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Listbox, Need to change number of items in List (not the items)
    By Kalithro in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-14-2013, 09:23 PM
  2. Replies: 2
    Last Post: 12-23-2011, 11:04 AM
  3. Possible to change the index numbers within a collection?
    By jerseyguy1996 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-02-2010, 09:53 AM
  4. Add substrings to collection as separate items
    By c4tin in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-14-2009, 12:47 PM
  5. [SOLVED] [SOLVED] Class Collection Add Items keep repeating
    By Kevin Vaughn in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-18-2006, 05:55 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1