Match and group strings in a list box

zenijos

New Member
Joined
Apr 16, 2015
Messages
1
I have some previously made code that I need to use and Im a little rusty on my Visual basic for applications.

There is a list in a form that is generated from a spreadsheet.

The items in the list are generated in the following format, "lawyer's name - charges he defends":

example:

Johnson - Reckless Driving
Johnson - Speeding
Williams - DUI
Williams - Reckless





Each line is a separate string and each string is attached to an integer in an accompanying spreadsheet.
So when you select

"Johnson - Reckless Driving" it returns a value equal to the number of Reckless Driving cases for Johnson.


You can select as many items from the list as you like and it will return the total of all selected items.

There are often 20 - 30 Names with up to 3 different charges following their names to choose.

All I need to do is create a function that groups all strings with the same name in a single value when multiple lawyers are selected.

If the above 4 names were selected the desired outcome would be to output the following:

Johnson - Reckless Driving - 10
Johnson - Speeding - 5
Williams - DUI - 3
Williams - Reckless - 2


Johnson Total: 15

Williams Total: 5


Grand total: 20

Basically, what I need is a function that will read each item in the list up to the hyphen then group items based on what it finds.



This seems pretty simple, but I'm rusty and don't really know where to begin. I will appreciate any insight or solutions.
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.

Forum statistics

Threads
1,223,275
Messages
6,171,121
Members
452,381
Latest member
Nova88

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