简体   繁体   English

在下拉列表独特价值

[英]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. 例如,我的输出文件中的名称“ SchemeID”指的是我的源文件中的相同名称。 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. 其他任何事情都需要两个中间的数据表或VBA来完成。 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. 在另一个工作表中(例如Sheet2),您将需要一个公式,该公式将从2个源名称中提取所有数据。 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. 据我所知,没有干净的非VBA方式可以合并到“命名范围”,因此我们需要通过将数据转储到工作表中然后再次进行拾取来实现。

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. 这将是一个非常凌乱的工作表,但是您可以根据需要将其隐藏,这并不是一个大问题,因为非VBA方法仍然需要数据转储表。

In Cell D1, we will put the number of rows in SchemeID, as follows: 在单元格D1中,我们将行数放入SchemeID中,如下所示:

=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): 在单元格D2中,我们将行数放在SchemeID2中(我假设这是第二个列表的名称,您未指定):

=ROWS(SchemeID2)

In column B we will be dumping in the data from both named lists, without sorting or eliminating duplicates. 在B列中,我们将转储两个命名列表中的数据,而不会进行排序或消除重复项。 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). 从A1开始并向下拖动,请按以下步骤进行操作(如果您希望使用页眉,则会变得有些棘手,因此我将假定没有页眉)。

=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 #. 这是说 - 如果该行不高于SchemeID总条目更多,然后拉在当前行#从SchemeID值。 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). 否则,从SchemeID2中提取条目,在当前行号减去SchemeID中的总行数(因此,如果我们在行10中,但是SchemeID在行4中结束,那么行10将在SchemeID2中提取第6个条目)。

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]: 现在在A列中,我们将检查哪一行是重复的,如下所示,从A2开始[A1硬编码为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. 这将检查当前行上方的行中B列中是否存在当前值的重复项。 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. 如果没有重复,则将索引号加1。

In cell D3, put the following formula to track how many unique IDs there are: 在单元格D3中,输入以下公式以跟踪有多少个唯一ID:

=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]: 接下来,在C列,把你的新的列表,因为有[拖累]从B列拉了许多独特价值:

=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]: 这将简化为[假设D3说的话,假设C列中有20行数据]:

='Sheet2!R1C3:R20C3'

Which, in the R1C1 method of referencing, means Sheet2!C1:C20. 在R1C1引用方法中,它表示Sheet2!C1:C20。

This new named range should be what your dropdown lists refer to on your other tab. 这个新的命名范围应该是您的下拉列表在其他选项卡上引用的范围。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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