Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Fast way to clear Listbox selection

I have a large Listbox in a Userform that has 5 columns and can have up
to 1200 row entries. I have run into a curious behavior.

I have buttons to Select all entries in the Listbox and to Clear all
selections in the Listbox. My code is virtually idential to do the
Select All and Clear All. Here's the curious part: when I have ~ 1000
rows in the Listbox, it takes ~ 3 seconds to do a Clear All, but only ~
1 second to do the Select All. With a small number of rows, it
impossible to see any difference, but with a large number of entries it
takes noticeably longer to do the clear I have written the Clear All
code as fast as I can think of (no calculations within the loop). I
also tried turning off screen updating and calculations, but it doesn't
seem to make any difference.

Does anyone know of a faster way to do the clear? Here is my code.

Private Sub btnClearAll_Click()
Dim I As Integer
Dim count As Integer

With NameForm.ListBox1
count = .ListCount - 1
For I = 0 To count
.Selected(I) = False
Next I
End With
End Sub

The only difference between the Clear All code and the Select All
codeis False/True in line .Selected(I) = False.
Any ideas? Why would be it faster to do the selection?

Any info would be appreciated,
Thanks,
Jim

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 770
Default Fast way to clear Listbox selection

Jim,

I tried turning off multiselect, setting the selection to none (-1) and
tunring multiselect back on. It seems to do what you want:

Private Sub btnClearAll_Click()
Me.ListBox1.MultiSelect = fmMultiSelectSingle
Me.ListBox1.ListIndex = -1
Me.ListBox1.MultiSelect = fmMultiSelectMulti
End Sub

hth,

Doug

wrote in message
ups.com...
I have a large Listbox in a Userform that has 5 columns and can have up
to 1200 row entries. I have run into a curious behavior.

I have buttons to Select all entries in the Listbox and to Clear all
selections in the Listbox. My code is virtually idential to do the
Select All and Clear All. Here's the curious part: when I have ~ 1000
rows in the Listbox, it takes ~ 3 seconds to do a Clear All, but only ~
1 second to do the Select All. With a small number of rows, it
impossible to see any difference, but with a large number of entries it
takes noticeably longer to do the clear I have written the Clear All
code as fast as I can think of (no calculations within the loop). I
also tried turning off screen updating and calculations, but it doesn't
seem to make any difference.

Does anyone know of a faster way to do the clear? Here is my code.

Private Sub btnClearAll_Click()
Dim I As Integer
Dim count As Integer

With NameForm.ListBox1
count = .ListCount - 1
For I = 0 To count
.Selected(I) = False
Next I
End With
End Sub

The only difference between the Clear All code and the Select All
codeis False/True in line .Selected(I) = False.
Any ideas? Why would be it faster to do the selection?

Any info would be appreciated,
Thanks,
Jim



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 694
Default Fast way to clear Listbox selection

Hi,
When swithing from multiselect to singleselect, the listbox is rebuilt
internaly, and the selection is cleared. I don't kow if it is faster with
large list but it is easy and convenient:

Private Sub CommandButton1_Click()
With ListBox1
.MultiSelect = fmMultiSelectSingle
.MultiSelect = fmMultiSelectMulti 'switch back to multi
End With
End Sub

I hope this helps
--
Regards,
SĂ©bastien
<http://www.ondemandanalysis.com


"Doug Glancy" wrote:

Jim,

I tried turning off multiselect, setting the selection to none (-1) and
tunring multiselect back on. It seems to do what you want:

Private Sub btnClearAll_Click()
Me.ListBox1.MultiSelect = fmMultiSelectSingle
Me.ListBox1.ListIndex = -1
Me.ListBox1.MultiSelect = fmMultiSelectMulti
End Sub

hth,

Doug

wrote in message
ups.com...
I have a large Listbox in a Userform that has 5 columns and can have up
to 1200 row entries. I have run into a curious behavior.

I have buttons to Select all entries in the Listbox and to Clear all
selections in the Listbox. My code is virtually idential to do the
Select All and Clear All. Here's the curious part: when I have ~ 1000
rows in the Listbox, it takes ~ 3 seconds to do a Clear All, but only ~
1 second to do the Select All. With a small number of rows, it
impossible to see any difference, but with a large number of entries it
takes noticeably longer to do the clear I have written the Clear All
code as fast as I can think of (no calculations within the loop). I
also tried turning off screen updating and calculations, but it doesn't
seem to make any difference.

Does anyone know of a faster way to do the clear? Here is my code.

Private Sub btnClearAll_Click()
Dim I As Integer
Dim count As Integer

With NameForm.ListBox1
count = .ListCount - 1
For I = 0 To count
.Selected(I) = False
Next I
End With
End Sub

The only difference between the Clear All code and the Select All
codeis False/True in line .Selected(I) = False.
Any ideas? Why would be it faster to do the selection?

Any info would be appreciated,
Thanks,
Jim




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 770
Default Fast way to clear Listbox selection

Sébastien,

Interesting. I didn't think to try it like that.

Doug

"sebastienm" wrote in message
...
Hi,
When swithing from multiselect to singleselect, the listbox is rebuilt
internaly, and the selection is cleared. I don't kow if it is faster with
large list but it is easy and convenient:

Private Sub CommandButton1_Click()
With ListBox1
.MultiSelect = fmMultiSelectSingle
.MultiSelect = fmMultiSelectMulti 'switch back to multi
End With
End Sub

I hope this helps
--
Regards,
Sébastien
<http://www.ondemandanalysis.com


"Doug Glancy" wrote:

Jim,

I tried turning off multiselect, setting the selection to none (-1) and
tunring multiselect back on. It seems to do what you want:

Private Sub btnClearAll_Click()
Me.ListBox1.MultiSelect = fmMultiSelectSingle
Me.ListBox1.ListIndex = -1
Me.ListBox1.MultiSelect = fmMultiSelectMulti
End Sub

hth,

Doug

wrote in message
ups.com...
I have a large Listbox in a Userform that has 5 columns and can have up
to 1200 row entries. I have run into a curious behavior.

I have buttons to Select all entries in the Listbox and to Clear all
selections in the Listbox. My code is virtually idential to do the
Select All and Clear All. Here's the curious part: when I have ~ 1000
rows in the Listbox, it takes ~ 3 seconds to do a Clear All, but only ~
1 second to do the Select All. With a small number of rows, it
impossible to see any difference, but with a large number of entries it
takes noticeably longer to do the clear I have written the Clear All
code as fast as I can think of (no calculations within the loop). I
also tried turning off screen updating and calculations, but it doesn't
seem to make any difference.

Does anyone know of a faster way to do the clear? Here is my code.

Private Sub btnClearAll_Click()
Dim I As Integer
Dim count As Integer

With NameForm.ListBox1
count = .ListCount - 1
For I = 0 To count
.Selected(I) = False
Next I
End With
End Sub

The only difference between the Clear All code and the Select All
codeis False/True in line .Selected(I) = False.
Any ideas? Why would be it faster to do the selection?

Any info would be appreciated,
Thanks,
Jim






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Fast way to clear Listbox selection

Thanks Doug and Sebastien,
Now almost instantaneous even with large list.

Much appreciated!

Jim

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
How To Clear Previous Selection From a Drop Down The Griffster Excel Discussion (Misc queries) 3 September 22nd 10 09:36 PM
How do I clear a print area when the selection is grayed out? Ron Excel Discussion (Misc queries) 0 July 24th 07 11:28 PM
ListBox selection GMet Excel Programming 1 September 24th 04 08:02 PM
How to clear a selection Nathan Gutman Excel Programming 4 February 26th 04 03:12 PM
How to Clear value a listbox! bookworm98[_6_] Excel Programming 5 January 27th 04 04:38 AM


All times are GMT +1. The time now is 04:29 PM.

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

About Us

"It's about Microsoft Excel"