Is it possible to recover the selected values from a multiselect (not active X) list box?

Asked

Viewed 693 times

2

It is possible to recover the selected values from a list box (Form control) with the option of multiple selection, by formula or Vba?

segue a imagem do controle que quero recuperar os valores

  • 1

    It is. But what have you tried? Try to produce a [mcve] (if only by illustrating your scenario with short images), so that those interested in helping you can better understand where exactly is your difficulty.

  • I understand perfectly, but the case is that I imagine doing it by VBA.

  • 1

    Well, then your question is: "how to access the value of a combobox (list box) in Excel?". This has nothing to do with Activex and does not necessarily depend on VBA. Because another thing you need to make clear is whether you are talking about a VBA Control itself, or a native Excel validation list.

  • 1

    Thank you Luiz. I’m talking about a list box. In this case I am not interested in a validation list, because I need the user to have the option to select more than 1 item. So when the user selects 2 or 3 items, I need to somehow know what these items are. I would like to do this using a form control and not an Active X.

  • Ah, ok. In this case you already have your answer in Cod 2 from colleague @dot.Py’s reply (the controls in the Excel Developer tab are not Activex).

  • Not yet Luiz, po in the case it references an active control X and not that of a form control. I can not reference a fomulário control via VBA. I think I will have to use the controls Active x same.

  • 1

    Ué... the code is exactly the same to reference a control added via Developer tab. If it’s not serving you, maybe it’s because your difficulty isn’t even clear. Why don’t you edit the question and provide an example (small images help) of what you’re doing?

  • I followed your recommendation.

Show 3 more comments

1 answer

2


Yes, it is possible. You should create a loop p/ check each of the items in the listbox and do what you want.


COD 1

Dim k As Long
Dim s As String

For k = 0 To List1.ListCount - 1
    If List1.Selected(k) Then
        s = List1.List(k)
        ' ... fazer algo com o item selecionado
    End If
Next

COD 2

Dim lItem As Long

For lItem = 0 To List1.ListCount - 1    
    If List1.Selected(lItem) = True Then    
        MsgBox(List1.List(lItem))    
    End If    
Next    

Or, if these above codes don’t work, you can try running the proposed model in that reply.


EDIT: to learn how to manipulate list boxes, take a look at this link.

  • But this is an example for an Active X control, right? How to do the same for a control that is not Active x?

  • 2

    @slide this link can help you...

  • Perfect! That’s right! Edit your answer so I put as answered.

  • @Get Done. Good that worked!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.