跳到主要内容

如何从Excel中的列范围中动态提取唯一值列表?

对于定期更改值的列范围,无论更改如何,您始终需要从该范围中获取所有唯一值。 如何制作唯一值的动态列表? 本文将向您展示如何处理它。

使用公式从列范围动态提取唯一值列表
使用VBA代码从列范围动态提取唯一值列表


使用公式从列范围动态提取唯一值列表

如下图所示,您需要从范围B2:B9中动态提取唯一值列表。 请尝试以下数组公式。

1.选择一个空白单元格,例如D2,在其中输入以下公式,然后按 按Ctrl + 转移 + 输入 同时键。 (B2:B9是您要提取唯一值的列数据,D1是您的公式所在的上方单元格)

=IFERROR(INDEX($B$2:$B$9, MATCH(0,COUNTIF($D$1:D1, $B$2:$B$9), 0)),"")

2.继续选择单元格D2,然后向下拖动“填充手柄”以获取指定范围内的所有唯一值。

现在,将提取列范围B2:B9中的所有唯一值。 当此范围内的值更改时,唯一值列表将立即动态更改。

在excel中轻松选择并突出显示所有唯一值:

选择重复和唯一单元格 实用程序 Kutools for Excel 可以帮助您轻松选择并突出显示所有唯一值(包括第一个重复项)或仅出现一次的唯一值,以及您需要的重复值,如下图所示。
立即下载 Kutools for Excel! (30 天免费试用)


使用VBA代码从列范围动态提取唯一值列表

您还可以使用以下VBA代码从列范围中动态提取唯一值列表。

1。 按 其他 + F11 同时打开 Microsoft Visual Basic应用程序 窗口。

2.在 Microsoft Visual Basic应用程序 窗口中,单击 插页 > 模块。 然后将以下VBA代码复制并粘贴到 模块 窗口。

VBA代码:从范围中提取唯一值列表

Sub CreateUniqueList()
Dim xRng As Range
Dim xLastRow As Long
Dim xLastRow2 As Long
Dim I As Integer
On Error Resume Next
Set xRng = Application.InputBox("Please select range:", "Kutools for Excel", Selection.Address, , , , , 8)
If xRng Is Nothing Then Exit Sub
On Error Resume Next
xRng.Copy Range("D2")
xLastRow = xRng.Rows.Count + 1
ActiveSheet.Range("D2:D" & xLastRow).RemoveDuplicates Columns:=1, Header:=xlNo
xLastRow2 = Cells(Rows.Count, "B").End(xlUp).Row
For I = 1 To xLastRow2
  If ActiveSheet.Range("D2:D" & xLastRow2).Cells(I).Value = "" Then
     ActiveSheet.Range("D2:D" & xLastRow2).Cells(I).Delete
  End If
Next
End Sub

备注:在代码中,D2是您将找到唯一值列表的单元格。 您可以根据需要进行更改。

3.回到工作表,单击 插页 > 形状 > 长方形。 看截图:

4.在工作表中绘制一个矩形,然后输入一些需要在其上显示的单词。 然后右键单击它并选择 分配宏 从右键单击菜单中。 在里面 分配宏 对话框中,选择 创建唯一列表 ,在 宏名 框,然后单击 OK 按钮。 看截图:

5.现在,单击矩形按钮, Kutools for Excel 弹出对话框,请选择包含您需要提取的唯一值的范围,然后单击 OK 按钮。

从现在开始,您可以重复上述步骤5以自动更新唯一值列表。


相关文章:

最佳办公生产力工具

🤖 Kutools 人工智能助手:基于以下内容彻底改变数据分析: 智能执行   |  生成代码  |  创建自定义公式  |  分析数据并生成图表  |  调用 Kutools 函数...
热门特色: 查找、突出显示或识别重复项   |  删除空白行   |  合并列或单元格而不丢失数据   |   不使用公式进行四舍五入 ...
超级查询: 多条件VLookup    多值VLookup  |   跨多个工作表的 VLookup   |   模糊查询 ....
高级下拉列表: 快速创建下拉列表   |  依赖下拉列表   |  多选下拉列表 ....
列管理器: 添加特定数量的列  |  移动列  |  切换隐藏列的可见性状态  |  比较范围和列 ...
特色功能: 网格焦点   |  设计图   |   大方程式酒吧    工作簿和工作表管理器   |  资源库 (自动文本)   |  日期选择器   |  合并工作表   |  加密/解密单元格    按列表发送电子邮件   |  超级筛选   |   特殊过滤器 (过滤粗体/斜体/删除线...)...
前 15 个工具集12 文本 工具 (添加文本, 删除字符,...)   |   50+ 图表 类型 (甘特图,...)   |   40+ 实用 公式 (根据生日计算年龄,...)   |   19 插入 工具 (插入二维码, 从路径插入图片,...)   |   12 转化 工具 (小写金额转大写, 货币兑换,...)   |   7 合并与拆分 工具 (高级组合行, 分裂细胞,...)   |   ... 和更多

使用 Kutools for Excel 增强您的 Excel 技能,体验前所未有的效率。 Kutools for Excel 提供了 300 多种高级功能来提高生产力并节省时间。  单击此处获取您最需要的功能...

产品描述


Office Tab 为 Office 带来选项卡式界面,让您的工作更加轻松

  • 在Word,Excel,PowerPoint中启用选项卡式编辑和阅读,发布者,Access,Visio和Project。
  • 在同一窗口的新选项卡中而不是在新窗口中打开并创建多个文档。
  • 每天将您的工作效率提高50%,并减少数百次鼠标单击!
Comments (35)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
con este procedimiento de filtro se hace de forma muy rapida

1.EN ESTE EJEMPLO los datos a remover los duplicados estan en la col A de la fila 59 a la 239
2. se define un criterio de filtrado en este caso en la fila d56 el mismo titulo de la lista a remover duplicados y la d57 la dejo en blanco
3. una vez ejecutado se muestran los datos en la fila destino, que en mi caso fue la d59

Range("A59:A239").AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=Range _
("D56:D57"), CopyToRange:=Range("D59"), Unique:=True
This comment was minimized by the moderator on the site
I would like to be able to do this exact same thing, except using two separate column ranges (B2:B9) as well as (D2:D9) is this possible?
This comment was minimized by the moderator on the site
Hi Anthony,
You can place the results in the same column as the original data. Such as column B in this case.
But you need to reference the top cell of the result cell in the formula as follows.
=IFERROR(INDEX($B$2:$B$9, MATCH(0,COUNTIF($B$11:B11, $B$2:$B$9), 0)),"") + Ctrl + Shift + Enter
This comment was minimized by the moderator on the site
Ik heb gemerkt dat de 'formule'-methode erg traag werkt bij grote datasets. Een goed alternatief is het gebruik van een draaitabel. Kies dan alleen de rijlabels, je krijgt dan een lijstje met unieke waarden. Het kan zijn dat je wat extra's krijgt "(leeg)" bijvoorbeeld. Je kunt deze er vervolgens uitfilteren. Helaas kun je maar op 1 criterium filteren. Ook daar zijn wel weer oplossingen voor, maar dat is wat complexer.
This comment was minimized by the moderator on the site
how to make the vba code work for a range where another formula was used?on column B I have a formula, referring to columns D and E.
If I use apply the code to column L (let's say), (obviously, properly modifying the cells in the code) the macro returns the formula applied to columns M and N... It works, then, but not as I want!How to keep the values in column B?thanks
This comment was minimized by the moderator on the site
thank you very much
This comment was minimized by the moderator on the site
I try the VBA Code and the formula. The code VBA is working very well but I can't keep a file with macro. But th problem is that I can't make the formula working. Did anybody have an idea ? Thank you
This comment was minimized by the moderator on the site
Hi Charlotte,
Thank you for your comment. You can keep the file with macro for future use by saving the workbook as an Excel Macro-Enabled Workbook.
For the formula problem, would you please provide a screenshot of your data? Thank you for your comment.
This comment was minimized by the moderator on the site
I'm using that =IFERROR(INDEX($B$2:$B$9, MATCH(0,COUNTIF($D$1:D1, $B$2:$B$9), 0)),"") formula which is great for one column but my data is spread across a range of columns and rows. Can I edit the formula to include the whole area? My data lives from AC4 to AR60...
This comment was minimized by the moderator on the site
Hi, thank you for your help.
Now, how can I have my values also sorted alphabetically? (I do not want to use the filter on my master table)
Should I use a COUNTIFS instead of COUNTIF?
Please HELP
This comment was minimized by the moderator on the site
Hi Alexis,
Sorry can't hep to sort the extracted value alphabetically at the same time with formula. Thank you for your comment.
This comment was minimized by the moderator on the site
I am trying to drag the formula down past my actual data so that I can input different sized data sets and not have to adjust anything. However, the last row after my actual data ends always returns a "0". I am using the unique values for something else in an adjacent column, and the 0 causes the last value to repeated (When I delete the 0 the value is no longer repeated). Any idea how to fix this? Also I am using Office 365 Business
This comment was minimized by the moderator on the site
If I do this for a thousand row excel sheet on the latest version of Excel on a Mac, it never returns. The first row works, but when I duplicate down, excel goes into a compute mode that has not returned values for over two hours now.

Any thoughts on how to do this for large lists (up to 2k rows) that will return 50 or 60 unique values?

I mocked this up in the "Numbers" app, and it's working perfectly there, taking only a couple minutes to calculate. It's just taking so long in Excel that I wonder if it will ever complete. I plan on letting it "run" overnight to see what will happen.
This comment was minimized by the moderator on the site
Check your Calculating options. It needs to be set to automatic. File > Options > Formulas > Calculating options > Workbook Calculation (Automatic selection)
There are no comments posted here yet
Load More
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations