Wednesday, April 27, 2011

Function Return The unique values in cell

suppose you have want to keep unique words in a cell

Like a1 is having ashish ashish koul

and i want only ashish koul as result ( remove duplicate words in cell) try the below function

check the snapshot

Here is the code:-

Function uniquetext(x As String)
Dim s As String
Dim jj, kk As Integer
Dim bl As Boolean
kk = 0

y = Split(x)
For i = LBound(y) To UBound(y)
bl = False
'jj = 0
For j = LBound(y) To i - 1
If y(i) = y(j) Then
bl = True
End If

' If jj >= kk Then
' Exit For
' End If
' kk = jj + 1
Next j

If bl = False Then
s = s & " " & y(i)
End If

Next i
uniquetext = Application.WorksheetFunction.Trim(s)
End Function

No comments:

Post a Comment

Import data from SQL

Macro to import data from SQL using ADO connection string: Sub Import_data_from_SQL() ' Tools -> References -> Microsoft Active...