Select ListBox entries

Takes a comma-separated list and selects matching entries of a ListBox.

Private Sub MarkMe(List As ListBox, Items As TextBox)
  Dim MergedData As Variant
  Dim iArray As Variant
 
  If (Not IsNull(Items.Value)) Then MergedData = Items.Value
 
  iArray = Split(MergedData, ",", -1, vbTextCompare)
 
  ' set everything to false (deselect all)
  For intI = 0 To List.ListCount
    List.Selected(intI) = False
  Next intI
 
  For Each curItem In iArray
    curItem = Trim(curItem)
    For intI = 0 To List.ListCount
      If List.ItemData(intI) = curItem Then
        List.Selected(intI) = True
        Exit For
      End If
    Next intI
  Next curItem
End Sub

 
snippets/vba/select-listbox-entries.txt · Last modified: 2008-07-15 23:20.31 by mbirth
 
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki Contents powered by Club-Mate Contents powered by BassDrive.com Labelled with ICRA