Summing Total and "unique" Total of items from a list

roscoe

Well-known Member
Joined
Jun 4, 2002
Messages
1,046
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Confusing title, I know, but couldn't think of a better one. I have a project of which I can't share any details (proprietary issues) for which I now have an odd requirement that I can't wrap my pea brain around.

I'll describe this best I can while staying vague. I need to look through a list for items that meet a certain criteria and (1) determine the total number of criteria-matching items, and (2) determine the total number of unique items. Analogy: I have a shopping cart with cans of food. I need the total of soup cans (i.e. 12 cans), and I need the total of soup flavors (i.e. 4 cans of tomato, 3 Chicken Noodle and 5 Clam Chowder equals a "flavor" count of 3).

I have no issue looping through the sheet and counting criteria-matching values, but I'm stumped at comparing each item to previous to assess whether to count it as a unique item or not. Manually I'd create a list of "flavors" and when I encounter another count of soup (Increment total by 1) I'd check the list to see if "Tomato" is on the list and if not add it. At the end I'd count the number of items in the "flavor" list. I just can't figure out the logic of this in a VBA loop.

Thanks in advance!
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Idea: I think I read that trying to add a duplicate item to a collection and/or dictionary is not allowed...can I just add items as I go and if the code tries to add a duplicate it just gets ignored? That way I get a unique list at the end (so long as I'm counting every instance for the total as I go)

How would I do that?
 
Upvote 0
Disregard...yes, I was able to keep a counter of matches, and then push the item to a collection. If it already existed, it wouldn't load (using On error resume next to keep it running).
 
Upvote 0

Forum statistics

Threads
1,214,643
Messages
6,120,702
Members
448,980
Latest member
CarlosWin

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