+ Reply to Thread
Results 1 to 9 of 9

Assign ListBox by code

  1. #1
    Registered User
    Join Date
    11-21-2007
    Posts
    21

    Assign ListBox by code

    Hi,

    I'm trying to assign a list box to a variable using Set statement, but getting an error.
    Please Login or Register  to view this content.
    what am i doing wrong?

    Thanks!!
    yonyon

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    More to the point what exactly are you trying to do? Why would you want to do thios?
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Registered User
    Join Date
    11-21-2007
    Posts
    21
    I'm trying to have dynamic lists in 3 (or more) listboxes - A, B and C.
    according to selection in listbox A, the list of B is automatically updated (according to a specific range..)
    so i have the procedure for that.
    now i want to do the same thing for when selecting a value in listbox B with the values of listbox C.
    so instead of having 2 similar procedure (for A anb B, and for B and C), I'd like to have only one with parameters.
    two of the parameters are source-listbox and target-listbox, hence my query...

    thanks!

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259
    Hello yonyon7,

    Where are the ListBoxes located: on a worksheet, or UserForm? Where is the macro code located?

    Sincerely,
    Leith Ross

  5. #5
    Registered User
    Join Date
    11-21-2007
    Posts
    21
    All listboxes are located in VBA userform, and the procedure is in the form code (ni each listbox click event).

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259
    Hello yonyon7,

    The your new objects will be available only as long as the Click event is active. To make the objects persist while the UserForm is running, place the DIm statements in the General Declarations section (Very top) of the UserForm.

    Sincerely,
    Leith Ross

  7. #7
    Registered User
    Join Date
    11-21-2007
    Posts
    21

    Problem Resolved

    It works when variables are defined as variants instaed of listbox..
    This one works:
    Please Login or Register  to view this content.
    While this one doesn't:

    Please Login or Register  to view this content.
    Thanks!
    Yonyon

  8. #8
    Registered User
    Join Date
    11-21-2007
    Posts
    21
    Hi Leith,

    Declaration was initially at the very top, it didn't work. As mentioned, it only worked once declared as variant rather than ListBox.

    Thanks,
    Yonyon

  9. #9
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259
    Hello yonyon7,

    Two other declaration methods should work also...
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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