So I'm trying to get how many unique categories I have in my data range and I know how to do it in Excel
=SUMPRODUCT(1/COUNTIF(général!N2:N229;général!N2:N229))
but when I try to use it via VBA i get a type mismatch error.
WorksheetFunction.SumProduct(1 / Application.WorksheetFunction.CountIf(Range("N2:N229"), Range("N2:N229")))
x4 = Worksheets("général").Cells(Rows.Count, 14).End(xlUp).Row
'x4=229
WorksheetFunction.SumProduct(1 / WorksheetFunction.CountIf(Range("N2:N"& x4), Range("N2:N" & x4)))
WorksheetFunction.SumProduct(1 / WorksheetFunction.CountIf(Worksheets("général").Range("N2:N" & x4), Worksheets("général").Range("N2:N" & x4)))
Can someone help me? It's driven me insane.
In VBA the worksheet functions do not behave exactly in the same way. You can use
Evaluate, writing the formulas as they are and using range addresses. But a better way would be using aScripting.Dictionary. Please, try the next code, which will return the unique values number, but also which are these unique values and how many per each (in columns "O:P"):To
Evaluatethe worksheet function, please try the next piece of code: