Highlight multiple items in listbox based on textbox item

G

Gizzmo

I have a user form with a ListBox2 (which represents a list fo
'facility' code and description) that is populated when the form i
Initialized.

I also have a text box that represents the same 'facility' that i
populated when the user selects an item from a second ListBox1 (whic
looks at existing records on a spreadsheet and brings back records base
on a series of combo box selections made by the user).

What I would like to be able to do is once the tex box has bee
populated by selecting ListBox1, I would like for the items (NB: ther
can be multiple items in the text box i.e. I have a string of text i
the Facility code on the spreadsheet seperated by a carriage return i
the cell) that are now in the text box to be highlighted in List Box 2!

At the moment I have code that is able to populate the text box once th
user highlights multiple items in List Box 2 and exits, but I want t
able to do the revers i.e. have the items become highlighted in List Bo
2 (before the user has taken any action) based on the items in the tex
box.

Can any one help
 
G

Gizzmo

I have solved my problem thanks.

If you are interested here is snippet of the code


Code
-------------------

.txtFacility.Value = ListBox1.List(r, 8)

Dim var() As String
Dim x As Integer
Dim y As Integer
Dim st As String

st = ListBox1.List(r, 8)

x = InStr(1, st, Chr(13))
'x = InStr(1, st, ",")
var = Split(st, Chr(13))
'var = Split(st, ",")

For x = 0 To UBound(var)
For y = 0 To Me.ListBox2.ListCount - 1
'If Me.ListBox2.ListIndex(y) = var(x) Then
' If InStr(1, UCase(Trim(Me.ListBox2.List(y, 0))), UCase(Trim(var(x))), vbTextCompare) > 0 Then
If StrComp(Me.ListBox2.List(y, 0), var(x), vbTextCompare) = 0 Then

'If UCase(Trim(Me.ListBox2.List(y, 0))) = UCase(Trim(var(x))) Then
Debug.Print UCase(Trim(Me.ListBox2.List(y, 0)))
Debug.Print UCase(Trim(var(x)))
Me.ListBox2.Selected(y) = True

Exit For

End If
Next

Next

Code
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top