Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old January 19th, 2008, 02:50 PM
Registered User
Join Date: Jan 2008
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default For repeated ComboBoxes Count Selected Items


I have 40 ComboBoxes on a form... each ComboBox contains two items... for example item A and item B.... I have also added two textboxes on the form....I want one textbox to count total number of A items selected and the other textbox to count total number of B items selected....

Grateful if you could help and explain how to do above in Excel VBA

Thanks and Regards...A. Borhani
Old March 24th, 2008, 06:49 PM
Authorized User
Join Date: Mar 2008
Posts: 35
Thanks: 0
Thanked 1 Time in 1 Post

Supposing your comboboxes are all named "ComboBox" plus the serial number 1, 2, 3, ...
You can loop through them and check the ListIndex property of each one. ListIndex=0 means first row selected, ListIndex=1 means second row selected.
There's a button in your Userform which when pressed counts the selected items and shows the result in two textboxes.
Private Sub btnCountComboSelections_Click()
Dim i As Integer, Count1 As Integer, Count2 As Integer
For i = 1 To 40 '<-- 40 ComboBoxes
   If Me.Controls("ComboBox" & i).ListIndex = 0 Then
      Count1 = Count1 + 1
      Count2 = Count2 + 1
   End If
Me.TextBox1.Text = CStr(Count1)
Me.TextBox2.Text = CStr(Count2)
End Sub

Similar Threads
Thread Thread Starter Forum Replies Last Post
DropDownList, DataSource and Selected Items kingroon ASP.NET 2.0 Basics 2 February 25th, 2008 10:41 AM
Number of selected items in a listbox sarah lee ASP.NET 2.0 Basics 2 May 17th, 2007 12:20 PM
matches without repeated items pongup BOOK: Beginning Regular Expressions 0 April 7th, 2007 09:05 PM
Cannot have multiple items selected in a DropDownL Ron Howerton ASP.NET 1.0 and 1.1 Basics 23 November 8th, 2006 04:29 PM
selected items in asp:ListBox jtyson Classic ASP Basics 2 July 2nd, 2004 12:01 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.