Excel udf: Filter unique distinct values (case sensitive)
Filed in Excel, Unique distinct values, User defined functions (udf), vba on May.03, 2011. Email This article to a Friend
How to use udf
- Select cell range D3:D10
- Type =CSUnique(B3:B10) in formula bar.
- Press and hold CTRL + SHIFT
- Press Enter once
- Release all keys
Excel user defined function:
Function CSUnique(rng As Range)
Dim cell As Range, temp() As String, i As Single, iRows As Integer
ReDim temp(0)
For Each cell In rng
For i = LBound(temp) To UBound(temp)
If temp(i) = cell Then
i = i + 1
Exit For
End If
Next i
i = i - 1
If temp(i) <> cell Then
temp(UBound(temp)) = cell
ReDim Preserve temp(UBound(temp) + 1)
End If
Next cell
iRows = Range(Application.Caller.Address).Rows.Count
If iRows < UBound(temp) Then
temp(iRows - 1) = "More values.."
Else
For i = UBound(temp) To iRows
ReDim Preserve temp(UBound(temp) + 1)
temp(UBound(temp)) = ""
Next i
End If
CSUnique = Application.Transpose(temp)
End FunctionWhere to copy vba code?
- Press Alt-F11 to open visual basic editor
- Click Module on the Insert menu
- Copy and paste above vba code
- Exit visual basic editor
Download excel example file
Filter case sensitive unqiue distinct values.xls
(Excel 97-2003 Workbook *.xls)







Leave a Reply