Count items via VBA that occur only once in a range

NewOrderFac33

Well-known Member
Joined
Sep 26, 2011
Messages
1,283
Office Version
  1. 2016
  2. 2010
Platform
  1. Windows
Good afternoon,

Assuming I have the following items in a selected range: 1,2,2,2,3,4,4,5,6,6,7,7,8,8,9
can anyone suggest a VBA solution to display the number of items that occur in the list only ONCE?

In the above example, the answer would be 4 as only four numbers occur uniquely in the list (1, 3, 5 and 9).

If you can make it display those values too (e.g. "There are 4 items that occur only once: 1, 3, 5 and 9", that would be a bonus!)

As always, thanks in advance

Pete
 
Last edited:

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
How about
Code:
Sub NewOrderFac33()
   Dim Cl As Range
   Dim Ky As Variant
   
   With CreateObject("scripting.dictionary")
      For Each Cl In Selection
         If Not .Exists(Cl.Value) Then
            .Add Cl.Value, True
         Else
            .Item(Cl.Value) = False
         End If
      Next Cl
      For Each Ky In .Keys
         If Not .Item(Ky) Then .Remove Ky
      Next Ky
      Debug.Print Join(.Keys, ", "); " Are unique"
   End With
End Sub
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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