Dynamo Nath
Board Regular
- Joined
- Aug 5, 2009
- Messages
- 142
I've been trying to write a function to simplify finding the number of unique items in a list. And it works too except for the fact that it won't put the answer in the cell! Clicking the fx button to access the function screen and entering the range to check shows the anticipated result at the bottom but pressing ok doesn't transfer the result to the cell.
I'm sure it's fairly straight forwards but I'm fresh out of ideas. Thanks in advance, Nathan.
Code:
Public Function myUniqueDataCount(data_range)
Dim wibble As Range
Dim myrange As String
Dim myblanks As Integer
Dim myanswer As Integer
myblanks = Application.WorksheetFunction.CountBlank(data_range)
data_range.Name = "data_range"
If myblanks > 0 Then
myUniqueDataCount = "Data contains empty fields"
Exit Function
Else:
myanswer = Application.Evaluate("=SUM(IF(FREQUENCY((MATCH(data_range,data_range,0)), MATCH(data_range,data_range,0))>0,1))")
End If
myUniqueDataCount = myanswer 'this line might not be required but it was an attempt to resolve the problem.
End Function
I'm sure it's fairly straight forwards but I'm fresh out of ideas. Thanks in advance, Nathan.