+ Reply to Thread
Results 1 to 7 of 7

Control Toolbox ComboBox: Clear All cb when Worksheet Opens?

  1. #1
    Registered User
    Join Date
    04-08-2010
    Location
    Montreal
    MS-Off Ver
    2003 & 2010
    Posts
    16

    Control Toolbox ComboBox: Clear All cb when Worksheet Opens?

    Hello.

    Is it possible to clear the value and the item list of all comboboxes when the Workbook is opened? I have tried without success using an object such as this:

    Please Login or Register  to view this content.
    An error message pops up saying that the object does not support the method or property.

    Thanks!

  2. #2
    Forum Contributor
    Join Date
    10-18-2012
    Location
    Telford, England
    MS-Off Ver
    Excel 2010 (2003)
    Posts
    294

    Re: Control Toolbox ComboBox: Clear All cb when Worksheet Opens?

    It may not be as simple as that. I'm away from Excel on this computer so I'll have to guess.
    Assuming the loop is sound, and that the only OLEobjects are the comboboxes (i.e. no buttons), I think it would be obj.text = "".

  3. #3
    Registered User
    Join Date
    08-15-2012
    Location
    Las Vegas
    MS-Off Ver
    Excel 2010
    Posts
    87

    Re: Control Toolbox ComboBox: Clear All cb when Worksheet Opens?

    Try this and see if it works:

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    04-08-2010
    Location
    Montreal
    MS-Off Ver
    2003 & 2010
    Posts
    16

    Re: Control Toolbox ComboBox: Clear All cb when Worksheet Opens?

    Hello.

    brynbaker
    It doesn't work. I get the message "Object doesn't support this property or method". Same happened with "Obj.Clear".


    g8r777
    It doesn't work. There is no error, but the ComboBoxes are not Cleared. I guess because of the Else Statement, meaning that TypeName(obj) <> "ComboBox".

    I found this in the Help file:

    For a Controls collection, Clear deletes controls that were created at run time with the Add method. Using Clear on controls created at design time causes an error.

    If the control is bound to data, the Clear method fails.
    I still don<t know what to do.

    Thanks.

  5. #5
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Control Toolbox ComboBox: Clear All cb when Worksheet Opens?

    Try this.
    Please Login or Register  to view this content.
    By the way, the Clear method you posted the help for is for the Controls collection.
    Quote Originally Posted by Help
    Clear Method (Microsoft Forms)

    Removes all objects from an object or collection

    ....

    For a ListBox or ComboBox, Clear removes all entries in the list.

  6. #6
    Forum Contributor
    Join Date
    10-18-2012
    Location
    Telford, England
    MS-Off Ver
    Excel 2010 (2003)
    Posts
    294

    Re: Control Toolbox ComboBox: Clear All cb when Worksheet Opens?

    The easy way is as follows
    Please Login or Register  to view this content.
    Of course if you have complications (and who contacts a forum unless they do), a more elegant solution is desirable. But as I say, this is simple.
    If you have lots of comboxes you could even write a macro to generate the code.

    What we need, as you first posted is a loop; this works fine but only gets us so far as it does not tell us what we want!
    Please Login or Register  to view this content.
    Putting the name somewhere else would facilitate writing a list off macro commands for the first suggestion above. Unless you have thousands of checkboxes, make progress this way.

    The next refinement is to understand the object model. The Shapes collection manages common attribute of other objects it holds objects. I've been struggling recently with lack or or unhelpfully structured model documentation. Perhaps a person with 'tall shoulders' can advise.

  7. #7
    Forum Contributor
    Join Date
    10-18-2012
    Location
    Telford, England
    MS-Off Ver
    Excel 2010 (2003)
    Posts
    294

    Re: Control Toolbox ComboBox: Clear All cb when Worksheet Opens?

    I was about to post some more and carefully re-read your post. Some of my previous input was wrong due to a misreading and I apologies for any confusion.
    I think this will be more helpful:
    Please Login or Register  to view this content.
    I hope that helps.

+ 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