+ Reply to Thread
Results 1 to 5 of 5

VBA command works in Userform but not in Worksheet

  1. #1
    Registered User
    Join Date
    03-01-2011
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    2

    VBA command works in Userform but not in Worksheet

    I've wasted the last couple of hours trying to figure this out. I want to get the text of the selected value in a Form Controls listbox which is in a worksheet. In Excel 2003 I could just type:

    Sheets(1).Range("A1").Value = myListBox.Text

    The best I've been able to do in Excel 2007 is to get the index and that uses

    Sheets(1).Range("A1").Value = Sheets(1).ListBoxes(1).ListIndex

    The command works fine if I put the listbox in a userform instead, but I need to have it on a worksheet. I also don't understand why I have to use ListBoxes instead of whatever I name the listbox. Has MS changed something in 2007 or have I just done something wrong?

  2. #2
    Forum Expert Colin Legg's Avatar
    Join Date
    03-30-2008
    Location
    UK
    MS-Off Ver
    2003, 2007, 2010, 2013
    Posts
    1,252

    Re: VBA command works in Userform but not in Worksheet

    Hi,

    It's because you've inserted a "forms" listbox onto the worksheet rather than an "activeX" listbox. When you go to the ribbon to insert the control, you'll see that there are two banks of controls: "forms" and "activeX".
    Hope that helps,

    Colin

    RAD Excel Blog

  3. #3
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: VBA command works in Userform but not in Worksheet

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here
    Hope that helps.

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

    Free DataBaseForm example

  4. #4
    Registered User
    Join Date
    03-01-2011
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: VBA command works in Userform but not in Worksheet

    Worked like a charm. Thanks!!! Still, wasn't it possible to use the regular form controls in previous versions of excel?

  5. #5
    Forum Expert Colin Legg's Avatar
    Join Date
    03-30-2008
    Location
    UK
    MS-Off Ver
    2003, 2007, 2010, 2013
    Posts
    1,252

    Re: VBA command works in Userform but not in Worksheet

    Hi,
    Worked like a charm. Thanks!!! Still, wasn't it possible to use the regular form controls in previous versions of excel?
    Please add code tags around your code in post #1 and then I will edit this reply to answer this question.

+ 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