Multiplication of values based on multiple listbox selections

Hi, really hope someone can help me with this one, I don't know VB at all, this is a new challenge for me and cant seem to resolve through web searching...

I am using Excel 2016.

So I have learned how to create an ActiveX listbox, how to populate the listbox and turn on MultiSelect.

My listbox currently shows the "Options" Range Column A (below)

My range of selected cells are;

Column A

Options

Option 1

Option 2

Option 3

Option 4

Column B

Corresponding Numerical Value

1.4

4.2

2.0

9.1

What I want to be able to do is when I select say Option 1 and Option 3 or any combination, is to show an output into a specific worksheet cell, the product from the corresponding value of Column B

Eg if I click on Option 1 and Option 3 in the listbox the worksheet cell value would show "2.8" the sum of 1.4 x 2.0

Many thanks in advance for some help on next steps.

Re: Multiplication of values based on multiple listbox selections

Welcome to VBForums :wave:

*Thread moved from the 'VB.Net' forum to the 'Office Development/VBA' forum.*

Re: Multiplication of values based on multiple listbox selections

you need to loop through the list items, get the values from the selected items like

Code:

`Dim tot As Double`

tot = 1

With ListBox1

For i = 0 To .ListCount - 1

If .Selected(i) Then tot = tot * .List(i, 1)

Next

End With

MsgBox tot

change name of listbox to suit, note you need to start with a base value of 1, if you use the default value of 0 you total will be 0

Re: Multiplication of values based on multiple listbox selections

Hi Westconn1

Thats a great help, thank you.

I am just stuck now on how to put the output of the sum into a cell on the worksheet... I have put a linkedcell into the properties, but nothing is showing in the cell.

I have populated the listbox with option 1 to 4

Unfortunately, even though I can go into the VB editor... how do I to apply this code to listbox1?... sorry about this but really am new to vba, and not sure if i am doing this right.

Again thanks for any support.

1 Attachment(s)

Re: Multiplication of values based on multiple listbox selections

Screenshot to show you where i am at... need my hand held on this one. Once I understand I will be able to apply to my little mini project.

Attachment 168597

Re: Multiplication of values based on multiple listbox selections

the basic would be

Code:

`range("b7").value = tot`

in place of the messagebox

if you are working with multiple worksheets, or the cell for the result is not on the active sheet, then may would have to fully qualify the range, possibly starting like workbook.worksheet.range