Sum amount for selected item in listbox

  • Thread starter Thread starter SF
  • Start date Start date
S

SF

Hi,

I have a listbox on a form that allow multiple selection of row. The
rowsourcde of the listbox has 2 column, ID and AmountPaid (Currency).

I want to sum the AmountPaid of the selected item within a listbox. How can
I acheive that?

SF
 
Loop through the ItemsSelected property of the listbox and add up the
values; note that the values will be text and you'll need to convert back to
numeric to ensure valid result:

Dim varItemSel As Variant
Dim dblSum As Double
dblSum = 0
For Each varItemSel In Me.NameOfListBox.ItemsSelected
dblSum = dblSum + CDbl(Me.NameOfListBox.Column(2,varItemSel)
Next varItemSel
MsgBox dblSum
 
Drat -- lost a parenthesis somewhere.

Here is corrected code snippet:

Dim varItemSel As Variant
Dim dblSum As Double
dblSum = 0
For Each varItemSel In Me.NameOfListBox.ItemsSelected
dblSum = dblSum + CDbl(Me.NameOfListBox.Column(2,varItemSel))
Next varItemSel
MsgBox dblSum
 
Back
Top