Option Explicit
Private Sub CommandButton1_Click()
Dim choices As Integer, pick As Integer, a As Integer
Dim Multply(6) As Single, Answer As Single
For choices = 1 To 6
For pick = 0 To Me.Controls("ListBox" & choices).ListCount - 1
With Me.Controls("ListBox" & choices)
If .Selected(pick) Then
Multply(choices) = Multply(choices) + Multiplier(choices, pick)
End If
End With
Next pick
If Multply(choices) = 0 Then Multply(choices) = 1
Next choices
MsgBox "Will multiply these values:" & vbCrLf & _
Multply(1) & vbCrLf & _
Multply(2) & vbCrLf & _
Multply(3) & vbCrLf & _
Multply(4) & vbCrLf & _
Multply(5) & vbCrLf & _
Multply(6)
Answer = 1 'answer has to start as 1, otherwise, it'll always be zero
For a = 1 To 6 'a = 1 to the number of listboxes
Answer = Multply(a) * Answer
Next a
Label1.Caption = Answer
End Sub
Private Function Multiplier(whichList As Integer, whichSelection As Integer) As Single
Select Case whichList
'this outer bunch of cases needs to have 1 case for each listbox
'this example uses 6 so i have 6 outer cases
Case 1: 'options in first listbox
Select Case whichSelection + 1
'these inner bunch of cases, need 1 for each possible selection for that box
'(so a box with 4 options would have 4 cases here)
Case 1: Multiplier = 1 'these numbers are the multipliers for each option
Case 2: Multiplier = 2
Case 3: Multiplier = 3
End Select
Case 2: 'options in second listbox
Select Case whichSelection + 1
Case 1: Multiplier = 1
Case 2: Multiplier = 2
Case 3: Multiplier = 3
End Select
Case 3: 'options in third listbox
Select Case whichSelection + 1
Case 1: Multiplier = 1
Case 2: Multiplier = 2
Case 3: Multiplier = 3
End Select
Case 4: 'options in fourth listbox
Select Case whichSelection + 1
Case 1: Multiplier = 1
Case 2: Multiplier = 2
Case 3: Multiplier = 3
End Select
Case 5: 'options in fifth listbox
Select Case whichSelection + 1
Case 1: Multiplier = 1
Case 2: Multiplier = 2
Case 3: Multiplier = 3
End Select
Case 6: 'options in sixth listbox
Select Case whichSelection + 1
Case 1: Multiplier = 1
Case 2: Multiplier = 2
Case 3: Multiplier = 3
End Select
End Select
End Function
Private Sub CommandButton2_Click()
Unload Me
End Sub
Private Sub UserForm_Initialize()
CommandButton1.Caption = "Calculate"
CommandButton2.Caption = "Done"
Label1.Font.Size = 20
Label1.Caption = "answer"
ListBox1.MultiSelect = fmMultiSelectMulti
ListBox2.MultiSelect = fmMultiSelectMulti
ListBox3.MultiSelect = fmMultiSelectMulti
ListBox4.MultiSelect = fmMultiSelectMulti
ListBox5.MultiSelect = fmMultiSelectMulti
ListBox6.MultiSelect = fmMultiSelectMulti
ListBox1.AddItem "#1, option 1"
ListBox1.AddItem "#1, option 2"
ListBox1.AddItem "#1, option 3"
ListBox2.AddItem "#2, option 1"
ListBox2.AddItem "#2, option 2"
ListBox2.AddItem "#2, option 3"
ListBox3.AddItem "#3, option 1"
ListBox3.AddItem "#3, option 2"
ListBox3.AddItem "#3, option 3"
ListBox4.AddItem "#4, option 1"
ListBox4.AddItem "#4, option 2"
ListBox4.AddItem "#4, option 3"
ListBox5.AddItem "#5, option 1"
ListBox5.AddItem "#5, option 2"
ListBox5.AddItem "#5, option 3"
ListBox6.AddItem "#6, option 1"
ListBox6.AddItem "#6, option 2"
ListBox6.AddItem "#6, option 3"
End Sub