Showing posts with label UniqueList. Show all posts
Showing posts with label UniqueList. Show all posts

Tuesday, August 9, 2011

Get Unique List : Another Method


if You want to get Unique list from a Range ,You ca use this array Function :

Function GetUniqueList(rng As Range) As Variant

On Error Resume Next
 
    Dim Arr() As Variant
    Dim cell As Range
    Dim r, c As Integer
    Dim i, j As Integer
    i = 0: j = 0
   
    With Application.Caller
    r = .Rows.Count
    c = .Columns.Count
    End With
    ReDim Arr(r - 1, c - 1)

    For Each cell In rng
    If WorksheetFunction.CountIf(rng.Cells(1, 1).Resize(cell.Row, 1), cell.Value) = 1 Then
        Arr(i, j) = cell.Value
        If j = c Then j = j + 1
        i = i + 1
        End If
       
     For k = i To UBound(Arr())
     Arr(k, 0) = ""
     Next
    Next
    GetUniqueList = Arr
End Function

Friday, August 5, 2011

Extract Unique List :

if you want to Extract Unique Value From a List , you can use this UDF :

Function UniqueList(rng As Range, Pos As Long) As String Dim List() As String
    Dim cell As Range
    Dim i As Long
    Dim t As Long
    i = 0
ReDim List(rng.Cells.Count) As String
For Each cell In rng
flag = 0
                    For t = LBound(List) To UBound(List)
                       If cell.Value = List(t) Then
                 
                        flag = 1
                        Exit For
                        End If
                        Next
                           
                            If flag = 0 Then
                            List(i) = cell.Value
                            i = i + 1
                            End If
Next
UniqueList = List(Pos)
End Function