Extract Unique Values from Single Row

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
It works for me. I have onl United State as a result as the other 2 columns contains an error
 
Upvote 0
I checked it from other PC with Excel 2007, and above file works well for all 4 occurrence of function.

Just one issue... if cell contains only numerical value then function didn't include numerical value. but alpha numerical, numerical with special character works properly.

Can you please include only numerical value into count? And is there any reason why function didn't work properly while accessing from my office pc with Excel 2010?
 
Upvote 0
I checked it from other PC with Excel 2007, and above file works well for all 4 occurrence of function.

Just one issue... if cell contains only numerical value then function didn't include numerical value. but alpha numerical, numerical with special character works properly.

Can you please include only numerical value into count? And is there any reason why function didn't work properly while accessing from my office pc with Excel 2010?

The following admits also numeric values, using an often-quoted ACONCAT function...

G2, control+shift+enter, not just enter, and copy down:
Rich (BB code):
=REPLACE(aconcat(IF(TRANSPOSE(FREQUENCY(IF($B2:$F2<>"", 
  MATCH("~"&$B2:$F2,$B2:$F2&"",0)),COLUMN($B2:$F2)-COLUMN($B2)+1)),", "&$B2:$F2,"")),1,2,"")

For this formula to work, you need to install the ACONCAT code, using Alt+F11...


ACONCAT is a function coded in <ACRONYM title="visual basic for applications">VBA</ACRONYM>, which is given below. You need to add this to your workbook using Alt+F11 in order to run the foregoing formula.

Function aconcat(a As Variant, Optional sep As String = "") As String
' Harlan Grove, Mar 2002
Dim y As Variant
If TypeOf a Is Range Then
For Each y In a.Cells
aconcat = aconcat & y.Value & sep
Next y
ElseIf IsArray(a) Then
For Each y In a
aconcat = aconcat & y & sep
Next y
Else
aconcat = aconcat & a & sep
End If
aconcat = Left(aconcat, Len(aconcat) - Len(sep))
End Function
 
Upvote 0
Hello Aladin,

I have implemented your given formula and it worked like a charm.

Thank you very much.

Regards,
Edwin
 
Upvote 0
I see Aladin already gave you formula which works nice, here is my corrected solution.

I changed a bit code, you need to provide there Range from where you want to take Text and then there is logical variable (1/0 or True/False) if you select True then it will give you Unique values only, for formula will return all NON blank values.

Code:
Function rngCONC(Target As Range, q As Boolean) As String

Dim temp As Variant
Dim finalOutput As String

finalOutput = Empty

For Each temp In Target
If Not temp = Empty Then
    If q = False Then
        If finalOutput = Empty Then
            finalOutput = temp
        Else
            finalOutput = finalOutput & ", " & temp
        End If
    Else
        If InStr(finalOutput, temp) = 0 Then
            If finalOutput = Empty Then
                finalOutput = temp
            Else
                finalOutput = finalOutput & ", " & temp
            End If
        End If
    End If
End If
Next temp

rngCONC = finalOutput

End Function

you can run (need to be run only once) below code to add Help Description for the formula
Code:
Sub DescribeFunction_rngCONC()
   Dim FuncName As String
   Dim FuncDesc As String
   Dim Category As String
   Dim ArgDesc(1 To 2) As String

   FuncName = "rngCONC"
   FuncDesc = "Concatenate text from selected range"
   Category = 7 'Text category
   ArgDesc(1) = "Range that needs to be concatenated"
   ArgDesc(2) = "Is a logical value (False or True): ""False"" to include each text from selected range, ""True"" for UNIQUE values only"

   Application.MacroOptions _
      Macro:=FuncName, _
      Description:=FuncDesc, _
      Category:=Category, _
      ArgumentDescriptions:=ArgDesc
End Sub
 
Upvote 0
Can't think of anything at the moment for X number of unique values. But the best way is to use the bottom one and extract in different cells.

Maybe some expert will suggest further and continue from here on. Would be interesting to follow.
 
Upvote 0
I have great respect for all experts here, from which I have learnt alot, but Aladin amazes me with his formulas. Thanks Aladin
 
Upvote 0

Forum statistics

Threads
1,215,754
Messages
6,126,680
Members
449,328
Latest member
easperhe29

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top