Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 260
Default Count number of selected item in Listbox

Hey guys what is the code to count the number of selected
items in a listbox. I know how to count the total number
of items in a listbox but how do you count the total
number of items that are selected?


Thank you
Todd Huttenstine
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 260
Default Count number of selected item in Listbox

This is a followup to my original post:

I came up with the following code...

Dim Counter As Long
Counter = 0
With ListBox1
For i = 0 To .ListCount - 1
ListValue = .List(i)
If .Selected(i) = True Then
Counter = Counter + 1
End If
Next
MsgBox Counter
End With

Can anyone tell me if there is a more effecient way of
doing this?


Thanks
Todd Huttenstine




-----Original Message-----
Hey guys what is the code to count the number of selected
items in a listbox. I know how to count the total number
of items in a listbox but how do you count the total
number of items that are selected?


Thank you
Todd Huttenstine
.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Count number of selected item in Listbox

Dim Counter As Long
Counter = 0
With ListBox1
For i = 0 To .ListCount - 1
If .Selected(i) = True Then
Counter = Counter + 1
End If
Next
MsgBox Counter
End With

No reason to assign the list value to listvalue

Why are you worried about this? There is no built in count you can access.
You must have some pretty tight code if you are worried about this
efficiency.

--
Regards,
Tom Ogilvy

"Todd Huttenstine" wrote in message
...
This is a followup to my original post:

I came up with the following code...

Dim Counter As Long
Counter = 0
With ListBox1
For i = 0 To .ListCount - 1
ListValue = .List(i)
If .Selected(i) = True Then
Counter = Counter + 1
End If
Next
MsgBox Counter
End With

Can anyone tell me if there is a more effecient way of
doing this?


Thanks
Todd Huttenstine




-----Original Message-----
Hey guys what is the code to count the number of selected
items in a listbox. I know how to count the total number
of items in a listbox but how do you count the total
number of items that are selected?


Thank you
Todd Huttenstine
.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Count number of selected item in Listbox

Dim i As Long
Dim c As Long

With Me.ListBox1
For i = 0 To .ListCount - 1
If .Selected(i) Then
c = c + 1
End If
Next i
End With

MsgBox c & " items selected"


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Todd Huttenstine" wrote in message
...
Hey guys what is the code to count the number of selected
items in a listbox. I know how to count the total number
of items in a listbox but how do you count the total
number of items that are selected?


Thank you
Todd Huttenstine



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Count number of selected item in Listbox

Thank you

Yes I need to count the number of selected items in the
listbox as a validation. I have items(week numbers for
each month) in the listbox tied to pivotfields(weeks worth
of data) in pivot tables. I have a pivot table underneath
the pivot table I am manipulating with the listbox. I
want to ensure that a user does not select more than 6
pivotfields (in the listbox) so it does not build the
pivot table on top of the second pivot table below. A
user will never need to select more than 6 months of data
because there are no more than 6 full/incomplete weeks in
any givin month.



Todd
-----Original Message-----
Dim Counter As Long
Counter = 0
With ListBox1
For i = 0 To .ListCount - 1
If .Selected(i) = True Then
Counter = Counter + 1
End If
Next
MsgBox Counter
End With

No reason to assign the list value to listvalue

Why are you worried about this? There is no built in

count you can access.
You must have some pretty tight code if you are worried

about this
efficiency.

--
Regards,
Tom Ogilvy

"Todd Huttenstine"

wrote in message
...
This is a followup to my original post:

I came up with the following code...

Dim Counter As Long
Counter = 0
With ListBox1
For i = 0 To .ListCount - 1
ListValue = .List(i)
If .Selected(i) = True Then
Counter = Counter + 1
End If
Next
MsgBox Counter
End With

Can anyone tell me if there is a more effecient way of
doing this?


Thanks
Todd Huttenstine




-----Original Message-----
Hey guys what is the code to count the number of

selected
items in a listbox. I know how to count the total

number
of items in a listbox but how do you count the total
number of items that are selected?


Thank you
Todd Huttenstine
.



.

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 count the number of selected combobox within Excel? Eric Excel Discussion (Misc queries) 10 June 30th 09 09:20 AM
Last Item of Listbox not getting displayed Raj Excel Discussion (Misc queries) 0 April 22nd 08 10:58 AM
Adding item in listbox volabos Excel Worksheet Functions 0 December 3rd 07 11:27 AM
Item order in ListBox [email protected] Excel Discussion (Misc queries) 1 June 16th 06 01:15 PM
Selected cells: item count versus summation Neal Zimm Excel Discussion (Misc queries) 3 October 9th 05 02:30 PM


All times are GMT +1. The time now is 05:22 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"