Help. I am really frustrated with this. I am so close but not quite there and I feel it should be an easy answer but I just can't quite get it.
I have a Userform with a multiple selection Listbox. Basically I have a base part number and the user hits a command button that brings up the listbox and they select/deselect the option suffix codes they want to add to the part number (final part number is the base number with the option suffixes separated by a "-"). That part works fine. The problem I am having is trying add and subtract the pricing of the options from the base price. Base price is shown below as xNumber (101.18 is the base price). The option prices are held in column 3 of my source range. I added the line Cells(31, 4).Value = xNumber + xLstBox.List(I, 2) to increment the base price which is held in cell D31 [Cells(31,4)]. How do I get it to subtract the option prices as they deselect their options?
I have a Userform with a multiple selection Listbox. Basically I have a base part number and the user hits a command button that brings up the listbox and they select/deselect the option suffix codes they want to add to the part number (final part number is the base number with the option suffixes separated by a "-"). That part works fine. The problem I am having is trying add and subtract the pricing of the options from the base price. Base price is shown below as xNumber (101.18 is the base price). The option prices are held in column 3 of my source range. I added the line Cells(31, 4).Value = xNumber + xLstBox.List(I, 2) to increment the base price which is held in cell D31 [Cells(31,4)]. How do I get it to subtract the option prices as they deselect their options?
VBA Code:
Sub Rectangle1_Click()
Dim xSelShp As Shape, xSelLst As Variant, I, J As Integer
Dim xV As String
Dim xNumber As Double
Set xSelShp = ActiveSheet.Shapes(Application.Caller)
Set xLstBox = ActiveSheet.ListBox1
xNumber = 101.18
If xLstBox.Visible = False Then
xLstBox.Visible = True
xSelShp.TextFrame2.TextRange.Characters.Text = "Select Options"
xStr = ""
xStr = Range("ListBoxOutput").Value
If xStr <> "" Then
xArr = Split(xStr, "-")
For I = xLstBox.ListCount - 1 To 0 Step -1
xV = xLstBox.List(I)
For J = 0 To UBound(xArr)
If xArr(J) = xV Then
xLstBox.Selected(I) = True
Exit For
End If
Next
Next I
End If
Else
xLstBox.Visible = False
xSelShp.TextFrame2.TextRange.Characters.Text = "Select Options"
For I = xLstBox.ListCount - 1 To 0 Step -1
If xLstBox.Selected(I) = True Then
xSelLst = xLstBox.List(I) & "-" & xSelLst
Cells(31, 4).Value = xNumber + xLstBox.List(I, 2)
End If
Next I
If xSelLst <> "" Then
Range("ListBoxOutput") = Mid(xSelLst, 1, Len(xSelLst) - 1)
Else
Range("ListBoxOutput") = ""
End If
End If
End Sub