Adding Listbox Values

survey4life

New Member
Joined
Oct 25, 2011
Messages
46
I have a listbox with several values which change and i want to add the all the values in that listbox. Here is my code:

Code:
lbTotal.Clear
Dim counter As Integer
Dim sum As Integer
For counter = lbTotal2.ListCount - 1 To 0 Step -1
    sum = sum + lbTotal2.List(counter)
Next counter
lbTotal.AddItem Format(sum, "#,##0.00")

The problem with my code is that it doesnt add the decimal values. It rounds up the starting numbers to nearest decimal place and shows result.
For e.g Listbox with the following values: 10.7 + 10.0 + 10.1 = 31.00
which is obviously not correct.

So, can someone please either edit my code or write a fresh code that adds values of a listbox including the decimal values.
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Declare sum as Double or Single - integers don't have decimals.
 
Upvote 0

Forum statistics

Threads
1,203,172
Messages
6,053,888
Members
444,692
Latest member
Queendom

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top