multicolumn listbox move or value set

  • Thread starter Thread starter Andrew Smith
  • Start date Start date
A

Andrew Smith

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
 
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
 
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.
 

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

Back
Top