+ Reply to Thread
Results 1 to 14 of 14

Multiselect ListBox can't find the name

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    03-09-2009
    Location
    Oslo, Norway
    MS-Off Ver
    Excel 2007
    Posts
    128

    Multiselect ListBox can't find the name

    Hi,

    I have a sheet named "Main" and multiselect listbox in this sheet.

    I've named the multiselect listbox "Test", in the window just above the column A, next to the formula/cell value input field

    However when trying to run a macro which is to return the selections in the multiselect listbox. I get an error i the VBA code that "object required".

    Sub Knapp9_Klikk()
    ' Submit knappen
    
    Dim lItem As Long
    
        For lItem = 0 To Test.ListCount - 1
    
            If Test.Selected(lItem) = True Then
    
                Main.Range("A65536").End(xlUp)(2, 1) = Test.List(lItem)
    
                Test.Selected(lItem) = False
    
            End If
    
        Next
    
    End Sub
    What I want the macro to do is bascially. Output for each option in the listbox either TRUE or FALSE. Where the first should be outputted in cell A1, then B1, C1, etc..

    I will then use the input created in these cell, for a later procedure..

    Hope someone can shed some light on this...

    PS!! I'm using Excel 2007 and Vista

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,317

    Re: Multiselect ListBox can't find the name

    Assuming that is in the worksheet code module, when you click the left hand dropdown above the code module in the VBEditor, does Test appear as an object?
    Everyone who confuses correlation and causation ends up dead.

  3. #3
    Forum Contributor
    Join Date
    03-09-2009
    Location
    Oslo, Norway
    MS-Off Ver
    Excel 2007
    Posts
    128

    Re: Multiselect ListBox can't find the name

    I'm not sure I understand where I am supposed to look for what you ask.

  4. #4
    Forum Contributor
    Join Date
    03-09-2009
    Location
    Oslo, Norway
    MS-Off Ver
    Excel 2007
    Posts
    128

    Re: Multiselect ListBox can't find the name

    The listBox is in the worksheet by the way

  5. #5
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,317

    Re: Multiselect ListBox can't find the name

    When you have that code module open in the VB Editor, there should be two dropdowns at the top of the code window. The one on the left contains the available objects, the one on the right shows the available events/methods for the selected object. If you look for Test in the left hand one, is it there or do you see another name for the listbox?

  6. #6
    Forum Contributor
    Join Date
    03-09-2009
    Location
    Oslo, Norway
    MS-Off Ver
    Excel 2007
    Posts
    128

    Re: Multiselect ListBox can't find the name

    I see.

    the only thing I can see is (General)

  7. #7
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,317

    Re: Multiselect ListBox can't find the name

    If it's a Forms control listbox, try this:
    Sub Knapp9_Klikk()
    ' Submit knappen
    
    Dim lItem As Long
    With Sheet23.Listboxes("Test")
        For lItem = 0 To .ListCount - 1
    
            If .Selected(lItem) = True Then
    
                Sheet23.Range("A65536").End(xlUp)(2, 1) = .List(lItem)
    
                .Selected(lItem) = False
    
            End If
    
        Next
    End With
    End Sub
    If it was an ActiveX control, you should see a name like Listbox1 in the Intellisense list.

  8. #8
    Forum Contributor
    Join Date
    03-09-2009
    Location
    Oslo, Norway
    MS-Off Ver
    Excel 2007
    Posts
    128

    Re: Multiselect ListBox can't find the name

    I picked the listbox without the activeX controll... Shown I create one with ActiveX?

  9. #9
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,317

    Re: Multiselect ListBox can't find the name

    Did you try the code I just posted? It's for the non-ActiveX version of the control.

  10. #10
    Forum Contributor
    Join Date
    03-09-2009
    Location
    Oslo, Norway
    MS-Off Ver
    Excel 2007
    Posts
    128

    Re: Multiselect ListBox can't find the name

    Well... I'm off from work now... I'll have to look into this next week.

    I really appreciate your time.

+ 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