Count unique values with criteria

sharky12345

Well-known Member
Joined
Aug 5, 2010
Messages
3,404
Office Version
  1. 2016
Platform
  1. Windows
I've got this formula which counts the unique values in column A on the condition that the text in column E matches the criteria NORTH:

=SUM(IF("NORTH"='AUG CR'!$E$2:$E$45453, 1/(COUNTIFS('AUG CR'!$E$2:$E$45453, "NORTH",'AUG CR'!$A$2:$A$45453, 'AUG CR'!$A$2:$A$45453)), 0))

I really need this to be done by VBA though as the workbook is already quite large and I'm trying to reduce the amount of formulas used.

Can anyone assist please?
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Try this
VBA Code:
Sub CountUnique()
    Dim arr As Variant, i As Long, coll As New Collection, itm As String
    With ActiveSheet
        arr = .Range("A2", .Range("A" & .Rows.Count).End(xlUp)).Resize(, 5)
    End With
    For i = 1 To UBound(arr, 1)
        itm = UCase(arr(i, 5))
        If itm = "NORTH" Then
            itm = itm & arr(i, 1)
            On Error Resume Next
            coll.Add itm, itm
            On Error GoTo 0
        End If
    Next i
    MsgBox coll.Count, , "UNIQUE COUNT"
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,214,925
Messages
6,122,301
Members
449,078
Latest member
nonnakkong

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