Results 1 to 5 of 5
  1. #1
    4 Star Lounger
    Join Date
    May 2004
    Location
    Toronto, Ontario, Canada
    Posts
    425
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Listbox Multiselect (Excel 2000)

    Hi all,

    I want to know if someone had a good example of the Mulitselect properties for a listbox? What I would like to accomplish is turn a group of cells a different colour based on the selection.

    Thanks
    Darryl.

  2. #2
    WS Lounge VIP sdckapr's Avatar
    Join Date
    Jul 2002
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    11,225
    Thanks
    14
    Thanked 342 Times in 335 Posts

    Re: Listbox Multiselect (Excel 2000)

    Could you be more specific on what you have and want (perhaps attach an example) so that we can have it more related to what you want to do?

    Steve

  3. #3
    4 Star Lounger
    Join Date
    May 2004
    Location
    Toronto, Ontario, Canada
    Posts
    425
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Re: Listbox Multiselect (Excel 2000)

    Hi all,

    I thought I had it figured out, I thought the listbox index might look different having mulitselect instead of single select for the listbox index code. What I am trying to accomplish here is selecting multiple selections from within a listbox, and depending on the value of the index if true then turn the cell green. What I have now doesn't turn all of the cells green it only does 1 or 2 of the cells.

    Something else that I have tried to do is load the form by the value of the cells, but I can't figure it out. How do I read the value of the cell then put that value into the listindex so that when the form is loaded, it shows the listbox value plus shows the index as being selected?

    Private Sub UserForm_Initialize()
    ListBox1.List = getTurn
    If Range("A1").Interior.ColorIndex = 4 Then
    ListBox1.ListIndex(1) = True
    End If


    End Sub

    Thanks Darryl.

  4. #4
    WS Lounge VIP sdckapr's Avatar
    Join Date
    Jul 2002
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    11,225
    Thanks
    14
    Thanked 342 Times in 335 Posts

    Re: Listbox Multiselect (Excel 2000)

    1) Do not set the public function as a string. It needs to be a variant to read the array:

    <pre>Public Function getTurn()</pre>


    2) try this code for the commandbutton code:

    <pre>Private Sub CommandButton1_Click()
    Dim i As Integer
    Dim rng As Range
    Set rng = Worksheets("sheet1").Range("A1:A6")
    With ListBox1
    For i = 0 To .ListCount - 1
    If .Selected(i) Then
    rng.Cells(1).Offset(i, 0).Interior.ColorIndex = 4
    Else
    rng.Cells(1).Offset(i, 0).Interior.ColorIndex = xlNone
    End If
    Next
    End With
    End Sub</pre>


    Selected are colored, unselected have color cleared

  5. #5
    4 Star Lounger
    Join Date
    May 2004
    Location
    Toronto, Ontario, Canada
    Posts
    425
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Re: Listbox Multiselect (Excel 2000)

    Thanks Steve,

    I had tried to figure out the selected property, and put it into a loop, but I couldn't figure out the listcount.

    Thank you
    Darryl.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •