ListBox Multiple Selections - Adding/Subtracting Cell Values

Status
Not open for further replies.

Flapjack

Board Regular
Joined
Aug 24, 2005
Messages
61
Office Version
  1. 365
Platform
  1. Windows
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?

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
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Duplicate to: Listbox with Multiple Columns - adding values in Column to Spreadsheet Cell

In future, please do not post the same question multiple times. Per Forum Rules (#12), posts of a duplicate nature will be locked or deleted.

In relation to your question here, I have closed this thread so please continue in the linked thread. If you do not receive a response, you can "bump" it by replying to it yourself, though we advise you to wait 24 hours before doing so, and not to bump a thread more than once a day.
 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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