excelNewbie22
Well-known Member
- Joined
- Aug 4, 2021
- Messages
- 528
- Office Version
- 365
- Platform
- Windows
hi !
i'm using this formula in g2,
but when i applied it on a very large quantity of rows it gets slow, so i thought and manage to use a simpler formula like countif, in a longer (text wise) but much faster formula like in h2,
and now i want to do the same but with COUNTUNIQUE UDF, but it's more complicated, and i thought maybe some of you can help simplify it? since my above method wouldn't work on countunique
i'm using this formula in g2,
Excel Formula:
=SUM(--(COUNTIF(A3:F3,A2:F2)>0))
and now i want to do the same but with COUNTUNIQUE UDF, but it's more complicated, and i thought maybe some of you can help simplify it? since my above method wouldn't work on countunique
Cell Formulas | ||
---|---|---|
Range | Formula | |
G2 | G2 | =SUM(--(COUNTIF(A3:F3,A2:F2)>0)) |
H2 | H2 | =COUNTIF(A2:F2,A3)+COUNTIF(A2:F2,B3)+COUNTIF(A2:F2,C3)+COUNTIF(A2:F2,D3)+COUNTIF(A2:F2,E3)+COUNTIF(A2:F2,F3) |
G4 | G4 | =CountUnique(A4:D4,A5:D5) |
VBA Code:
Function CountUnique(r1 As Range, r2 As Range)
Dim i As Long, j As Long
Dim a As Variant, b As Variant
a = r1.Value
b = r2.Value
For i = 1 To UBound(a, 2)
For j = 1 To UBound(b, 2)
If b(1, j) = a(1, i) Then
CountUnique = CountUnique + 1
b(1, j) = "x"
Exit For
End If
Next
Next
End Function