Hi muralidaran,
I'll let Leith provide an answer on his fantastic code, but I'd thought I'd also post this as a possible alternative to simply return the count of the unique entries in a range:
Option Explicit
Sub Macro1()
Dim lngStartRow As Long
Dim strMyCol As String
Dim lngLastRow As Long
Dim dblUniqueCount As Double
lngStartRow = 2 'Starting row number for the data. Change to suit.
strMyCol = "B" 'Column letter containing the data. Change to suit.
lngLastRow = Cells(Rows.Count, strMyCol).End(xlUp).Row
On Error Resume Next
dblUniqueCount = Evaluate("SUM(IF(FREQUENCY(MATCH(" & strMyCol & lngStartRow & ":" & strMyCol & lngLastRow & "," & strMyCol & lngStartRow & ":" & strMyCol & lngLastRow & ",0),MATCH(" & strMyCol & lngStartRow & ":" & strMyCol & lngLastRow & "," & strMyCol & lngStartRow & ":" & strMyCol & lngLastRow & ",0))>=1,1,0))")
On Error GoTo 0
MsgBox dblUniqueCount
End Sub
Regards,
Robert
Bookmarks