+ Reply to Thread
Results 1 to 8 of 8

Multiselect listbox preselected values from matrix

Hybrid View

  1. #1
    Registered User
    Join Date
    04-24-2013
    Location
    Bristol
    MS-Off Ver
    Excel 2010
    Posts
    32

    Multiselect listbox preselected values from matrix

    Hi there

    How do I preselect items in a listbox based on combobox selection and values stored in matrix.

    I have attached the file with a description of what I mean

    Thanks
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Multiselect listbox preselected values from matrix

    Private Sub UserForm_Initialize()
    ComboBox1.List = Application.Transpose(Sheet1.Rows(2).SpecialCells(2).Offset(, 1).SpecialCells(2).Value)
    ListBox1.List = Sheet1.Columns(1).SpecialCells(2).Offset(1).SpecialCells(2).Value
    For j = 3 To 13
      If Sheet1.Cells(j, "D") = "X" Then ListBox1.Selected(j - 3) = True
    Next
    End Sub
    If solved remember to mark Thread as solved

  3. #3
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Multiselect listbox preselected values from matrix

    Hi Biffer

    Try this Combobox1 Change Code
    Option Explicit
    
    Private Sub ComboBox1_Change()
      Dim cNo As Long
      Dim Rng As Range, cel As Range
      With Sheet1.Rows(2)
        cNo = .Find(Me.ComboBox1.Value, LookAt:=xlWhole).Column
      End With
      Set Rng = Sheet1.Range(("A3"), Sheet1.Range("A3").End(xlDown))
      For Each cel In Rng
        If Intersect(Rows(cel.Row).EntireRow, Columns(cNo).EntireColumn) = "X" Then
          Me.ListBox1.Selected(cel.Row - 3) = True
        End If
      Next cel
    End Sub
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  4. #4
    Registered User
    Join Date
    04-24-2013
    Location
    Bristol
    MS-Off Ver
    Excel 2010
    Posts
    32

    Re: Multiselect listbox preselected values from matrix

    Jaslake, thanks...almost!

    If I select a name from the combobox, then select another name it aggregates the listbox selections

    How do I reset each time I select a name?

    Thanks

  5. #5
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Multiselect listbox preselected values from matrix

    Geez Biffer...ya didn't say you wanted THAT...try this
    Private Sub ComboBox1_Change()
      Dim cNo As Long, i As Long
      Dim Rng As Range, cel As Range
    
      For i = 0 To ListBox1.ListCount - 1
        If ListBox1.Selected(i) = True Then
          ListBox1.Selected(i) = False
        End If
      Next i
    
      With Sheet1.Rows(2)
        cNo = .Find(Me.ComboBox1.Value, LookAt:=xlWhole).Column
      End With
      Set Rng = Sheet1.Range(("A3"), Sheet1.Range("A3").End(xlDown))
      For Each cel In Rng
        If Intersect(Rows(cel.Row).EntireRow, Columns(cNo).EntireColumn) = "X" Then
          Me.ListBox1.Selected(cel.Row - 3) = True
        End If
      Next cel
    End Sub

  6. #6
    Registered User
    Join Date
    04-24-2013
    Location
    Bristol
    MS-Off Ver
    Excel 2010
    Posts
    32

    Re: Multiselect listbox preselected values from matrix

    Thought it was obvious

    Awesome - thanks for your help

  7. #7
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Multiselect listbox preselected values from matrix

    Actually, it was...just funning with you
    Thought it was obvious

  8. #8
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Multiselect listbox preselected values from matrix

    You're welcome...glad I could help. Thanks for the Rep.

    If this resolves your issue please mark your Thread as SOLVED.

    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Multiselect Listbox Returning Array of Selected Index Values
    By Draco1 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-27-2013, 06:46 PM
  2. Copy Selected items from multicolumn, multiselect listbox to another listbox
    By Willigb in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-19-2013, 11:27 AM
  3. Help! How do i populate a cell with the values selected from a multiselect listbox?
    By mamakamsi in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-12-2013, 11:48 AM
  4. Multiselect form listbox - selected values to be copied and pasted in a column
    By Ath01 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-04-2013, 01:37 AM
  5. MultiSelect Listbox get/use Values
    By Ikaabod in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-30-2007, 06:27 PM

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