Value retrieval from the Multiple selection dropdown in excel

ruts_1112

New Member
Joined
Mar 28, 2019
Messages
1
I am trying to make calculation from my dropdown menu. I have following dropdown in sheet 1 in my excel.
Category
AAA
BBB
CCC
DDD

<tbody>
</tbody>

In sheet 2, i have corresponding values for this dropdown.
Category
Value
AAA
1
BBB
2
CCC
3
DDD
4

<tbody>
</tbody>

I added VBA code for multiple selection and also added simple Vlookup formula to retrieve the value of category.

=VLOOKUP(E2;Sheet2!I2:J5;2;)

With the VBA code, i am able to select all three category and also remove the selected category later. But I am failing to retrieve the sum of selected category. For e.g. I want if customer chooses category AAA & CCC, he/she should be able to see sum as 4. Also if customer first chooses all three category and then removes one of the category then also the sum should get updated. I am not getting how do i update my Vlookup formula to get the sum.

Here is my VBA code for multiple selection.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
        'Updated: 2016/4/12
        Dim xRng As Range
        Dim xValue1 As String
        Dim xValue2 As String
        If Target.Count > 1 Then Exit Sub
        On Error Resume Next
        Set xRng = Cells.SpecialCells(xlCellTypeAllValidation)
        If xRng Is Nothing Then Exit Sub
        Application.EnableEvents = False
        If Not Application.Intersect(Target, xRng) Is Nothing Then
            xValue2 = Target.Value
            Application.Undo
            xValue1 = Target.Value
            Target.Value = xValue2
            If xValue1 <> "" Then
                If xValue2 <> "" Then
                    '                If xValue1 = xValue2 Or _
                    '                   InStr(1, xValue1, ", " & xValue2) Or _
                    InStr(1, xValue1, xValue2 & ",") Then
                    If InStr(1, xValue1, xValue2 & ",") > 0 Then
                        xValue1 = Replace(xValue1, xValue2 & ", ", "") ' If it's in the middle with comma
                        Target.Value = xValue1
                        GoTo jumpOut
                    End If
                    If InStr(1, xValue1, ", " & xValue2) > 0 Then
                        xValue1 = Replace(xValue1, ", " & xValue2, "") ' If it's at the end with a comma in front of it
                        Target.Value = xValue1
                        GoTo jumpOut
                    End If
                    If xValue1 = xValue2 Then        ' If it is the only item in string
                        xValue1 = ""
                        Target.Value = xValue1
                        GoTo jumpOut
                    End If
                    Target.Value = xValue1 & ", " & xValue2
                End If
                jumpOut:
            End If
        End If
        Application.EnableEvents = True
    End Sub
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest

Forum statistics

Threads
1,215,219
Messages
6,123,680
Members
449,116
Latest member
HypnoFant

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