You can FILTER
the original data and then count the number of unique instances.
Try =COUNT(UNIQUE(FILTER($A$2:$A$10, $B$2:$B$10=$D2)))
Here I assume that the original data is in cells A2:B10, and that the criteria for the filtering is in column D.
I have updated my answer to work for Office 2007 and mixed @Rory's comment to original post with my OFFSET
part of my previous Office 365 solution.
Plase the following formula in E2
:
=SUM(1/COUNTIFS(OFFSET($A$3,MATCH(D3,$A$3:$A$12,0)-1,1,COUNTIF($A$3:$A$12,D3),1),OFFSET($A$3,MATCH(D3,$A$3:$A$12,0)-1,1,COUNTIF($A$3:$A$12,D3),1)))
The OFFSET
part provides a list of consecutive rows that feature the Acc No
and belong to the same Br code . It uses MATCH
to determine the first occurance of the given Br code . As the anchor cell for the formula is the cell with the first content ( $A$3
), I subtract 1 from the MATCH
result. To determine the height, I use a COUNTIF
statement, that counts how many rows feature the current Br code .
The cell range provided by OFFSET
is then used as input for @Rory's COUNTIFS
solution.
The text and non-text (numeric) unique and distinct values in the column are quickly listed separately using VBA macro.
Sub GetCountDistinctValues()
Dim sayi As Long, rang As Range
With CreateObject("Scripting.Dictionary")
For Each rang In Range("A2:A" & Cells(Rows.Count, "A").End(xlUp).Row)
If rang <> Empty Then
If Not .Exists(rang.Value) Then
.Add rang.Value, Nothing
If IsNumeric(rang.Value) Then sayi = sayi + 1
End If
End If
Next
Range("C2").Value = .Count - sayi
Range("C3").Value = sayi
End With
End Sub
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.