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

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Declare sum as Double or Single - integers don't have decimals.
 
Upvote 0

Forum statistics

Threads
1,225,531
Messages
6,185,490
Members
453,297
Latest member
alvintranvcu123

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