Multiselect listbox selection question

  • Thread starter Thread starter Paul Mueller
  • Start date Start date
P

Paul Mueller

Is there a more efficient way to code this? I want to have some of the
selections within the listbox to be selected.
The code below works, but seems to me there should be a better way.

Sub Assembly()

UserForm1.ListBox1.Selected(0) = True
UserForm1.ListBox1.Selected(1) = True
UserForm1.ListBox1.Selected(2) = True
UserForm1.ListBox1.Selected(3) = True
UserForm1.ListBox1.Selected(4) = True
UserForm1.ListBox1.Selected(5) = True
UserForm1.ListBox1.Selected(6) = True
UserForm1.ListBox1.Selected(7) = True
UserForm1.ListBox1.Selected(8) = True
UserForm1.ListBox1.Selected(9) = True
UserForm1.ListBox1.Selected(10) = True
UserForm1.ListBox1.Selected(14) = True
UserForm1.ListBox1.Selected(18) = True
UserForm1.ListBox1.Selected(21) = True
UserForm1.ListBox1.Selected(23) = True
UserForm1.ListBox1.Selected(25) = True

End Sub



*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Hey Paul,

I would try this:

sub assembly()
for i = 0 to 25
UserForm1.ListBox1.Selected(i) = True
next
End Sub

This is of course assuming that the first 25 will always be selected. You
can use whatever variable you want in place of the 25 to get the correct
number selected.

Hope that helps!
-=Alejandro
 
Dim varr as Variant, i as long
varr = Array(0,1,2,3,4,5,6,7,8,9,10,14,18,21,23,25)
for i = lbound(varr) to ubound(varr)
Userform1.Listbox1.Selected(varr(i)) = True
Next
 

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