简体   繁体   中英

Unique Values in Drop Down List

I have two workbooks, a source file and an output file.

The source file contains information which occupies some drop-down lists in the output file.

For each drop-down list I have two 'names' (in the name manager) linked to it. For instance, the name 'SchemeID' in my output file refers to the same name in my source file. It consists of several rows/columns of data, and that populates my drop-down list.

There are some repeats in the source file (eg different names associated with the same number) which are appearing in the drop down lists, and I'd like to get rid of them so the list only displays unique values. Is it possible to do this using data from different workbooks?

The easiest way is oging to be to go to the source workbooks, Data Ribbon -> Remove Duplicates. Anything else will require a couple of in-between data sheets or VBA to do cleanly. If your data doesn't change option this manual method should be fine.

EDIT as you seem restricted from editing the Source File

In a different sheet (let's say Sheet2) you will need a formula which pulls in all of your data from your 2 source Names. To my knowledge there is no clean non-VBA way to combine to Named Ranges, so we will need to do this by dumping the data down to a sheet, and then picking it up again.

There are a lot of ways to do this, but I'm going to pick the one broken down to the most steps; it will be a pretty messy sheet, but you can hide it if you need to, which shouldn't be a huge concern as a non-VBA method will need a data dump sheet anyway.

In Cell D1, we will put the number of rows in SchemeID, as follows:

=ROWS(SchemeID)

In Cell D2, we will put the number of rows in SchemeID2 (which I assume is the name for your second list, which you didn't specify):

=ROWS(SchemeID2)

In column B we will be dumping in the data from both named lists, without sorting or eliminating duplicates. Do this as follows, starting at A1 and dragged down (if you want headers this gets a little trickier, so I will assume no headers).

=IF(ROW()<=$D$1,INDEX(SchemeID,ROW()),INDEX(SchemeID2,ROW()-$D$1)

This says - if the row is not more than the total entries in SchemeID, then pull the value from SchemeID at the current row #. Otherwise, pull the entry from SchemeID2, at the current row# less the total rows in SchemeID (so if we are at row 10, but SchemeID ends at row 4, then row 10 will pull the 6th entry from SchemeID2).

Now in Column A, we will be checking to see which row is a duplicate, as follows starting at A2 [A1 is hardcoded as 1]:

=IF(ISERROR(MATCH(B2,$B$1:B1,0)),A1+1,A1)

This checks to see if there's a duplicate of the current value in column B, in the rows above the current row. If there is, it keeps the same index # as the row above (which will be ignored when we use this as the index key next). If there's no duplicate, it adds 1 to the index number.

In cell D3, put the following formula to track how many unique IDs there are:

=MAX(A:A)

Next, in column C, put your new list, which pulls from column B for as many unique values as there are [drag down]:

=VLOOKUP(ROW(),A:B,0)

This is your new non-duplicate list. To make a clean reference to it, create a new named range with the following formula:

=INDIRECT("'Sheet2!R1C3:R"&'Sheet2!$D$3&"C3", FALSE)

This will simplify to [Assuming 20 rows of data in column C, bsaed on what D3 says]:

='Sheet2!R1C3:R20C3'

Which, in the R1C1 method of referencing, means Sheet2!C1:C20.

This new named range should be what your dropdown lists refer to on your other tab.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM