Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Multiselect listbox selection question

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!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Multiselect listbox selection question

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



"Paul Mueller" wrote in message
...
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!



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Multiselect listbox selection question



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

--
Regards,
Tom Ogilvy



"Paul Mueller" wrote in message
...
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!



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Multiselect listbox selection question

Perfect! Thank you very much.



*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Listbox selection ub Excel Discussion (Misc queries) 0 March 10th 09 06:43 PM
Multiselect Listbox use RKS Excel Discussion (Misc queries) 1 May 12th 06 03:04 PM
MultiSelect ListBox in Excel PeteSmith Excel Programming 1 April 20th 04 11:14 AM
Excel VBA-Looping though MultiSelect on ListBox jpendegraft[_3_] Excel Programming 2 February 3rd 04 04:38 PM
multiselect listbox CG Rosén Excel Programming 2 December 28th 03 05:17 PM


All times are GMT +1. The time now is 06:53 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"