ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   multicolumn listbox move or value set (https://www.excelbanter.com/excel-programming/307887-multicolumn-listbox-move-value-set.html)

Andrew Smith

multicolumn listbox move or value set
 
Hi,
In a multicolumn listbox excel userform is it possible to a)
initialize a listbox with one/several of the options already selected
as default and b) insert new items between pre-existing items (maybe
with AddItems followed by a move type command) ?

Thanks,
Andrew

Tom Ogilvy

multicolumn listbox move or value set
 
additem has a second argument stating location. It inserts the new value at
that point, so higher ordered items are moved up automatically. Here is an
example that populates a listbox with 0, 2, 4 and then inserts 3 and 1 so
the result is 0, 1, 2, 3, 4. It also then selects 0 and 3

Private Sub CommandButton1_Click()
ListBox2.Clear
ListBox2.MultiSelect = fmMultiSelectMulti
For i = 0 To 4 Step 2
ListBox2.AddItem i
Next
j = 3
For i = 2 To 1 Step -1
ListBox2.AddItem j, i
j = j - 2
Next
For i = 0 To ListBox2.ListCount - 1
If i Mod 3 = 0 Then
ListBox2.Selected(i) = True
End If
Next

--
Regards,
Tom Ogilvy



"Andrew Smith" wrote in message
om...
Hi,
In a multicolumn listbox excel userform is it possible to a)
initialize a listbox with one/several of the options already selected
as default and b) insert new items between pre-existing items (maybe
with AddItems followed by a move type command) ?

Thanks,
Andrew




Andrew Smith

multicolumn listbox move or value set
 
Thanks so much! You have been extremely helpful, do you work for this
site?


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Tom Ogilvy

multicolumn listbox move or value set
 
No, this is peer to peer support. Occasionally a Microsoft employee will
post, but they are usually clearly identied with [MSFT] or [MS] as part of
their from name. So most of the people here are sharing their experiences
and knowledge.

--
Regards,
Tom Ogilvy

"Andrew Smith" wrote in message
...
Thanks so much! You have been extremely helpful, do you work for this
site?


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!





All times are GMT +1. The time now is 09:36 AM.

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