ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How do I change the state of an item in a (form) multiselect list box (https://www.excelbanter.com/excel-programming/386922-how-do-i-change-state-item-form-multiselect-list-box.html)

[email protected]

How do I change the state of an item in a (form) multiselect list box
 
I have a multiselect list box in a form that I need to use to
manipulate some other data. I have already defeated the problem of
getting useful data out of the list box. The problem is that when the
form with the list box is loaded, it populates the list box from
scratch. How can I make the code select a specific entry?
Listname.List(i).Select does not work.

I can properly identify every list item that is being added and know
its position in the list (as well as a reference cell that indicates
if it should be selected). I just can't figure out how to select the
appropriate items.

Help would be greatly appreciated! Thanks!

Brian


Norman Jones

How do I change the state of an item in a (form) multiselect list box
 
Hi Brian,

Try usuing the ListBox's ListIndex property, the first item
is item 0, the second is item 1.

For example, to select the fourth item, try something like:

'=============
Private Sub UserForm_Initialize()
With Me.ListBox1
.ColumnCount = 4
.List = Range("A1:D20").Value
.ListIndex = 3
End With
End Sub
'<<=============

---
Regards,
Norman


wrote in message
ups.com...
I have a multiselect list box in a form that I need to use to
manipulate some other data. I have already defeated the problem of
getting useful data out of the list box. The problem is that when the
form with the list box is loaded, it populates the list box from
scratch. How can I make the code select a specific entry?
Listname.List(i).Select does not work.

I can properly identify every list item that is being added and know
its position in the list (as well as a reference cell that indicates
if it should be selected). I just can't figure out how to select the
appropriate items.

Help would be greatly appreciated! Thanks!

Brian




JLGWhiz

How do I change the state of an item in a (form) multiselect list
 
I'm not sure what you are after but:

ListBox1.Value = ListBox1.ListIndex(YourIndexNumber)

This should return the value of whichever index number you put in the
parentheses.

" wrote:

I have a multiselect list box in a form that I need to use to
manipulate some other data. I have already defeated the problem of
getting useful data out of the list box. The problem is that when the
form with the list box is loaded, it populates the list box from
scratch. How can I make the code select a specific entry?
Listname.List(i).Select does not work.

I can properly identify every list item that is being added and know
its position in the list (as well as a reference cell that indicates
if it should be selected). I just can't figure out how to select the
appropriate items.

Help would be greatly appreciated! Thanks!

Brian




All times are GMT +1. The time now is 12:28 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com