By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,157 Members | 891 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,157 IT Pros & Developers. It's quick & easy.

how to make totals of the items in a combo box

P: 1
I have got like 10 or so items (numbers) and i would like to have they totals. i.e item 1 + item 2 + item 3 + , etc.... As may items as found in the combo box
May 2 '14 #1
Share this Question
Share on Google+
1 Reply

P: 299
Expand|Select|Wrap|Line Numbers
  1.         Dim results As Integer
  3.         For Each itm In ComboBox1.Items
  4.             If Not itm = "" Then
  5.                 results = results + itm
  6.             End If
  7.         Next
The idea behind the code is that you specify an integer (a number) and continue adding to it. The For loop loops through each item in your combobox and if the item is not blank, then it adds it to the integer you specified and eventually creating a sum of all items.

You can display the results simply by adding something like the following to the end of the code:
Expand|Select|Wrap|Line Numbers
  1.         MsgBox(results)
May 2 '14 #2

Post your reply

Sign in to post your reply or Sign up for a free account.