By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,727 Members | 1,368 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,727 IT Pros & Developers. It's quick & easy.

Auto Select Items in Listbox based on Column value

P: 28
Good Afternoon,

I'm trying to auto-select items in a multi-select listbox based on a column's criteria in a VBA Sub. Here is my code thusfar that fails. All values are text data type. Any suggestions? Thanks.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim lngRow As Long
  3. Dim lbvalue As String
  4.  
  5. With Me.ListBox
  6.         For lngRow = 0 To List489.ListCount - 1
  7.             If (Me.ListBox.Column(2, lbvalue)) = "OC" Then
  8.                 ListBox.Selected(lngRow) = True
  9.             Else
  10.                 'ListBox.Selected(lngRow) = False
  11.             End If
  12.         Next
  13. End With
  14.  
  15.  
  16.  
Mar 17 '14 #1
Share this Question
Share on Google+
2 Replies


P: 28
Sorry. This line is incorrect
Expand|Select|Wrap|Line Numbers
  1. For lngRow = 0 To List489.ListCount - 1 
  2.  
It's really.
Expand|Select|Wrap|Line Numbers
  1. For lngRow = 0 To ListBox.ListCount - 1 
  2.  
  3.  
Mar 17 '14 #2

P: 28
Just figured it out. Thanks.

Expand|Select|Wrap|Line Numbers
  1. Dim lngRow As Long
  2.  
  3. With Me.Listbox
  4.         For lngRow = 0 To Listbox.ListCount - 1
  5.             If (Me.Listbox.Column(2, lngRow)) = "OC" Then
  6.                     Listbox.Selected(lngRow) = True
  7.             Else
  8.                     Listbox.Selected(lngRow) = False
  9.             End If
  10.         Next
  11. End With
  12.  
  13.  
  14.  
Mar 17 '14 #3

Post your reply

Sign in to post your reply or Sign up for a free account.