Formula to extract unique values to an array

  • Thread starter Thread starter QB
  • Start date Start date

QB

Board Regular
Joined
Jul 5, 2004
Messages
93
Hi

I have a column A1 to A750 with many duplicated values. I need a formula to extract the unique values from this column to an array. I want to use the array to act as a data validation list.

I would like to avoid using advanced filtering if possible.

Any help would be much appreciated.

QB
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
The worksheet with the column is generated using an OLE DB query to extract data from our accounting system's SQL Server database. A any changes to the query worksheet need to go through our IT Dept's change control process. I'm struggling to get my work completed for March month end without introducing delays from IT.
 
Upvote 0
It would probably only take one line of SQL code to extract unique values using the query.

Surely that wouldn't be a problem, or are the departments/people involved as stubborn as some I've met along the way.

Mind you the query problem doesn't really explain why you don't want to use advanced filter.

Using that method would have no impact, as far as I can see, on the query.:)
 
Upvote 0
The IT department are very uncomfortable in using the OLE DB query. Security on our live production DB is weak. The access I have gives me UPDATE capabilities over our live accounting tables! Scary!

I just wanted to use one of the wizzy formulae that Bill and Mike dream up in their podcasts to extract the unique values. Complex Excel is no problem but changing the worksheet or adding new SQL statements would be a bridge too far. The SQL is already complex - 4 joins, 2 sub-queries and complex grouping. There are 75 lines of SQL code in my query which is generated by VBA driven from an ad-hoc report parameter sheet.
 
Upvote 0
If you have a range of values (A1:A750), whether you use advanced filter or a formula seems they would accomplish the same, but I think in the end advanced filter would be easier to apply than a formula.

BTW, I do not have a formula to do what you ask.
 
Upvote 0
Hi

I have a column A1 to A750 with many duplicated values. I need a formula to extract the unique values from this column to an array. I want to use the array to act as a data validation list.

I would like to avoid using advanced filtering if possible.

Any help would be much appreciated.

QB

Let A1:A750 on Sheet1 house the data of interest.

Define Rvec by means of Insert|Name|Define as referring to:

=ROW(Sheet1!$A$1:$A$750)-ROW(Sheet1!$A$1)+1

B1:
Code:
=SUM(IF(FREQUENCY(IF($A$1:$A$750<>"",
    MATCH("~"&$A$1:$A$750&"",$A$1:$A$750&"",0)),Rvec),1))

B2, control+shift+enter (not just enter) and copy down:
Code:
=IF(ROWS($B$2:B2)<=$C$4,INDEX($A$1:$A$750,
   SMALL(IF(FREQUENCY(IF($A$1:$A$750<>"",
    MATCH("~"&$A$1:$A$750&"",$A$1:$A$750&"",0)),Rvec),Rvec),
      ROWS($B$2:B2))),"")
 
Upvote 0
Hi

Thanks for your response. I have tried it out but there seems to be a problem. Cell B1 entered as an array formula returns the number of unique values in the range. Cell B2 and the cells below return no value.

I have tried to trace the problem without success. I can see that the name Rvec and cell B1 do seem to generate arrays with the what look like a partial solution. After that I'm stuck - though the reference to cell $C$4 in the formula in B2 does confuse me.

I do hope that you can help me again.

Regards

QB
 
Upvote 0
Hi

Another option:

In C1, a formula like Aladin's to get the number of unique values:

=SUM(IF(FREQUENCY(IF($A$1:$A$750<>"",
MATCH("~"&$A$1:$A$750&"",$A$1:$A$750&"",0)),ROW($A$1:$A$750)-ROW($A$1)+1),1))

... confirmed with CSE

In B1:

=A1

In B2:

=IF(ROWS($B$1:B2)>$C$1,"",INDEX(A:A,MIN(IF(ISNA(MATCH($A$2:$A$750,$B$1:B1,0)),ROW($A$2:$A$750)))))

... confirmed with CSE

Copy down

P. S. I also think it would be easier to copy the list with the Advanced Filter.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,331
Members
452,636
Latest member
laura12345

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