Extracting Unique Values

cheongmarcus

New Member
Joined
Mar 14, 2020
Messages
16
Office Version
  1. 365
  2. 2016
  3. 2013
  4. 2011
Platform
  1. Windows
Hi everyone, I'm glad that this platform has helped to resolve my queries previously regarding excel. I need help on extracting unique values from 2 separate data set. It has more rows than these but i just extracted a sample to pose my question. Originally, Data set #1 is in worksheet 1 while data set #2 is in worksheet 2. To show it clearer, i have put in the same worksheet for now.

My question is: I want to extract unique values from these 2 data sets based on the month (if you see cell I2 to K2) using a formula. So each month will list out all the unique countries from both the list of countries combined.
Can anyone help me with this? Any help is much appreciated. Thank you.
1590128645277.png
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Hi, I'd like to provide a solution from a different perspective. It is easy to get a list of all country names of the world, store this list in one column, then user formula to check whether the country name and month exist in the datasource, if yes, then show it.
Book1.xlsx
ABCDEFGHI
1Data1Data2Country NameJanFebMar
2AJanAFebAAAC
3BJanCJanBBGE
4CMarZFebCCVM
5DJanVFebDDZ
6EMarBJanEF
7FJanMMarF
8GFebDJanG
9H
10I
11J
12K
13L
14M
15N
16O
17P
18Q
19R
20S
21T
22U
23V
24W
25X
26Y
27Z
Sheet1
Cell Formulas
RangeFormula
G2:G6,I2:I4,H2:H5G2=FILTER($E$2:$E$27,COUNTIFS($A$1:$A$1000,$E$2:$E$27,$B$1:$B$1000,G$1)+COUNTIFS($C$1:$C$1000,$E$2:$E$27,$D$1:$D$1000,G$1))
Dynamic array formulas.
 
Upvote 0
I see, thank you @shaowu459. May I know is it possible to not join both the list into one column but instead reference the lists separately?

because both the lists are actually in separate tabs and not within the same worksheet. And say if I have multiple tabs (e.g. 10 data sets instead of 2) I would prefer if i do not need to create an additional column to join all.

Thanks.
 
Upvote 0
Perhaps theis user-defined function might help. To implement ..
1. Right click the sheet name tab and choose "View Code".
2. In the Visual Basic window use the menu to Insert|Module
3. Copy and Paste the code below (can use the icon at the top right of the code pane below) into the main right hand pane that opens at step 2.
4. Close the Visual Basic window.
5. Enter the formula as shown in the screen shot below and copy across and down. (If you have more than 2 ranges then list them as further arguments in the function, separated by commas)
6. Your workbook will need to be saved as a macro-enabled workbook (*.xlsm)

VBA Code:
Function Country(sMonth As String, Num As Long, ParamArray Ranges() As Variant) As String
  Dim d As Object
  Dim a As Variant, Countries As Variant
  Dim i As Long, rng As Long
  
  Set d = CreateObject("Scripting.Dictionary")
  d.CompareMode = 1
  For rng = LBound(Ranges) To UBound(Ranges)
    a = Ranges(rng).Value
    For i = 1 To UBound(a)
      If InStr(1, d(a(i, 2)) & " ", " " & a(i, 1) & " ", 1) = 0 Then d(a(i, 2)) = d(a(i, 2)) & " " & a(i, 1)
    Next i
  Next rng
  Countries = Split(d(sMonth))
  If Num <= UBound(Countries) Then Country = Countries(Num)
End Function

cheongmarcus 2020-05-22 1.xlsm
AB
1Data2
2AApr
3CJan
4AApr
5VApr
6BJan
7MMar
8DJan
9XMar
10
Sheet2


cheongmarcus 2020-05-22 1.xlsm
ABCDEFGHIJKL
1Data1JanFebMarApr
2AJanA CA
3BJanB EV
4CMarC M 
5AJanD X 
6EMar    
7BJan    
8AApr
9
Sheet1
Cell Formulas
RangeFormula
I2:L7I2=Country(I$1,ROWS(I$2:I2),$A$2:$B$9,Sheet2!$A$2:$B$9)
 
Upvote 0
I see, thank you @shaowu459. May I know is it possible to not join both the list into one column but instead reference the lists separately?

because both the lists are actually in separate tabs and not within the same worksheet. And say if I have multiple tabs (e.g. 10 data sets instead of 2) I would prefer if i do not need to create an additional column to join all.

Thanks.
it is not easy to do that in formula, VBA method in post #4 is a better way for your case.
 
Upvote 0

Forum statistics

Threads
1,215,007
Messages
6,122,670
Members
449,091
Latest member
peppernaut

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