Counting unique instances across several (named) ranges

sandwichgirl

New Member
Hi

I've tried searching for a function that will calculate this answer, but am having trouble finding anything relevant relating to multiple ranges.

I've named my ranges to reduce my confusion and they are called onecraft, twocraft, threecraft, fourcraft etc (each is on a different worksheet and each contains a different number of rows). I want to count up how many different prices are contained across these ranges (whilst ignoring duplicates). I've tried sumproduct/countif, but from what I've read the countif can't cope with multiple ranges.

Is there a way to do this?

thanks in anticipation of my reduced frustration.

sandwichgirl

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
I don't know of a formula either, but if you don't mind VBA code, you might try this:
Code:
``````Sub countem()
With CreateObject("scripting.dictionary")
For Each e In Sheets("Sheet1").Range("onecraft")
If Not IsEmpty(e) And Not .exists(e.Value) Then .Add e.Value, 1
Next e
For Each e In Sheets("Sheet2").Range("twocraft")
If Not IsEmpty(e) And Not .exists(e.Value) Then .Add e.Value, 1
Next e
For Each e In Sheets("Sheet3").Range("threecraft")
If Not IsEmpty(e) And Not .exists(e.Value) Then .Add e.Value, 1
Next e
For Each e In Sheets("Sheet4").Range("fourcraft")
If Not IsEmpty(e) And Not .exists(e.Value) Then .Add e.Value, 1
Next e
MsgBox .Count & " unique items"
End With
End Sub``````
1. By unique I take it you mean each item counted only once, and not a count of only the items which occur only once. i.e. in the set a,b,a would you want only the b (1 unique) or a and b counted once each (two uniques). The code takes the latter approach, although easily modified to the other if you like.
2. If you don't mind your ranges being renamed, or even if you do, the code and its relevant entries could be shortened by including a loop.

=COUNTDIFF(ARRAY.JOIN(Onecraft,Twocraft,Threecraft),,"")

Hope this helps!

Replies
5
Views
112
Replies
7
Views
305
Replies
4
Views
134
Replies
4
Views
649
Replies
12
Views
1K

1,211,853
Messages
6,104,371
Members
447,902
Latest member
chriswebs23

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.

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

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