You are saving comma separated values into a textbox? You want to loop through the listbox items and select the items that match the names in the CSV string? Never heard of anything like this.
I don't see how a Debug.Print could produce any output from that code. An array is not declared and referenced that way in VBA. In this case because the dimensions of the array are unknown until populated by the Split() function, it must be declared as a variant variable. Example:
Code:
Dim varArray As Variant, x As Integer, z As Integer
varArray = Split("ABC, GHI, MNO", ", ")
For x = 0 To UBound(varArray)
For z = 0 To Listbox.ListCount - 1
If Listbox.Column(0, z) = varArray(x) Then Listbox.Selected(z) = True
Next
Next
This version clears and reselects at the same time.
Code:
Dim varArray As Variant, x As Integer, z As Integer, booMatch As Boolean
varArray = Split("ABC, GHI, MNO", ", ")
For z = 0 To Listbox.ListCount - 1
For x = 0 To UBound(varArray)
If Listbox.Column(0, z) = varArray(x) Then booMatch = True
Next
Listbox.Selected(z) = booMatch
booMatch = True
Next
A version without array:
Code:
Dim z As Integer
For z = 0 To Listbox.ListCount - 1
Listbox.Selected(z) = InStr("ABC, GHI, MNO", Listbox.Column(0, z)) > 0
Next
Instead of the text string in my example, reference your textbox.