提示:其他語言是Google翻譯的。 你可以訪問 English 版本。
登入
x
or
x
x
註冊
x

or

如何從Excel中的列範圍動態提取唯一值列表?

對於值範圍經常變化的列範圍,無論變化如何,您都需要從範圍中獲取所有唯一值。 如何製作獨特價值的動態列表? 本文將向您展示如何處理它。

使用公式從列範圍動態提取唯一值列表

用VBA代碼動態提取列範圍內的唯一值列表


輕鬆選擇和突出顯示excel中列範圍內的所有唯一值:

選擇重複和唯一單元格 實用程序 Kutools for Excel 可以幫助您輕鬆選擇並突出顯示所有唯一值(包括第一個重複項)或除第一個重複項外的唯一值以及重複值,如下圖所示。立即下載Kutools for Excel的全功能60天免費試用版!

Kutools for Excel:比200方便的Excel加載項,可以在60天免費試用。 立即下載免費試用版!

Office選項卡在Office中啟用選項卡式編輯和瀏覽,使您的工作更輕鬆......
Kutools for Excel解決了您的大多數問題,並使您的生產率提高了80%
  • 重用任何東西: 將最常用或最複雜的公式,圖表和其他任何內容添加到您的收藏夾中,並在將來快速重複使用它們。
  • 超過20文本功能: 從文本字符串中提取數字; 提取或刪除部分文字; 將數字和貨幣轉換為英文單詞。
  • 合併工具:將多個工作簿和工作表合二為一; 合併多個單元格/行/列,而不會丟失數據; 合併重複的行和總和。
  • 拆分工具:根據價值將數據分割成多個工作表; 一本工作簿可轉換為多個Excel,PDF或CSV文件; 一列到多列。
  • 粘貼跳過 隱藏/過濾行; 數和總和 按背景顏色; 將個性化電子郵件批量發送給多個收件人。
  • 超級過濾器: 創建高級過濾方案並應用於任何工作表; 分類 按週,日,頻率等; 過濾 通過大膽,公式,評論......
  • 超過300強大的功能; 與Office 2007-2019和365一起使用; 支持所有語言; 在您的企業或組織中輕鬆部署。

使用公式從列範圍動態提取唯一值列表

如下圖所示,您需要動態提取範圍為B2的唯一值列表:B9。 請嘗試下面的數組公式。

1。 選擇一個空白單元格,例如D2,輸入公式 =IFERROR(INDEX($B$2:$B$9, MATCH(0,COUNTIF($D$1:D1, $B$2:$B$9), 0)),"") (B2:B9是要提取唯一值的列數據,D1是公式所在的上面的單元格)插入到公式欄中,然後按 按Ctrl + 轉移 + 輸入 鍵同時。 看截圖:

2。 繼續選擇單元格D2,然後向下拖動填充手柄以獲取指定範圍內的所有唯一值。

現在提取列範圍B2:B9中的所有唯一值。 當此範圍內的值發生變化時,唯一值列表將立即動態更改。


用VBA代碼動態提取列範圍內的唯一值列表

您還可以使用以下VBA代碼從列範圍中動態提取唯一值列表。

1。 按 其他 + F11 鍵同時打開 Microsoft Visual Basic for Applications 窗口。

2。 在裡面 Microsoft Visual Basic for Applications 窗口中,單擊 插入 > 模塊。 然後復制並粘貼下面的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。 在工作表中畫一個矩形,然後輸入你需要顯示的一些單詞。 然後右鍵單擊它並選擇 分配宏 從右鍵單擊菜單。 在裡面 分配宏 對話框中選擇 CreateUniqueList宏名稱 框,然後單擊 OK 按鈕。 看截圖:

5。 現在點擊矩形按鈕,a Kutools for Excel 彈出對話框,請選擇包含您需要提取的唯一值的範圍,然後單擊 OK 按鈕。

從現在開始,您可以重複上述步驟5自動更新唯一值列表。


Office Tab - 在Excel中選項卡式瀏覽,編輯和管理工作簿:

Office選項卡將Web瀏覽器(如Google Chrome,Internet Explorer新版本和Firefox)中顯示的選項卡界面帶到Microsoft Excel。 它將是一個節省時間的工具,在您的工作中無可比擬。 見下面的演示:

點擊免費試用Office Tab!

Excel的Office選項卡


相關文章:


Kutools for Excel解決了您的大多數問題,並使您的生產率提高了80%

  • 重用: 快速插入 複雜的公式,圖表 以及你以前用過的任何東西; 加密單元格 密碼; 創建郵件列表 並發送電子郵件...
  • 超級方程式酒吧 (輕鬆編輯多行文字和公式); 閱讀佈局 (輕鬆讀取和編輯大量單元格); 粘貼到過濾範圍...
  • 合併單元格/行/列 不丟失數據; 分裂細胞含量; 組合重複的行/列...防止重複的細胞; 比較範圍...
  • 選擇複製或唯一 行; 選擇空行 (所有細胞都是空的); 超級查找和模糊查找 在許多工作簿中; 隨機選擇......
  • 精確複製 多個單元格而不更改公式參考; 自動創建參考 多張表; 插入項目符號,複選框等等......
  • 提取文本,添加文本,按位置刪除, 刪除空間; 創建和打印分頁小計; 在單元格內容和註釋之間轉換...
  • 超級過濾器 (將過濾方案保存並應用到其他工作表); 高級排序 按月/週/日,頻率等; 特殊過濾器 用粗體,斜體......
  • 結合工作簿和工作表; 根據鍵列合併表; 將數據拆分為多個表格; 批量轉換xls,xlsx和PDF...
  • 超過300強大的功能。 支持Office / Excel 2007-2019和365。 支持所有語言。 在您的企業或組織中輕鬆部署。 全功能30天免費試用。
kte tab 201905

Office選項卡為Office提供選項卡式界面,使您的工作更輕鬆

  • 在Word,Excel,PowerPoint中啟用選項卡式編輯和閱讀,Publisher,Access,Visio和Project。
  • 在同一窗口的新選項卡中打開並創建多個文檔,而不是在新窗口中。
  • 通過50%提高您的工作效率,每天為您減少數百次鼠標點擊!
官方底部
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    Charlotte · 4 months ago
    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
    • To post as a guest, your comment is unpublished.
      crystal · 3 months ago
      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.
  • To post as a guest, your comment is unpublished.
    Cameron · 4 months ago
    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...
  • To post as a guest, your comment is unpublished.
    Alexis · 9 months ago
    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
    • To post as a guest, your comment is unpublished.
      crystal · 7 months ago
      Hi Alexis,
      Sorry can't hep to sort the extracted value alphabetically at the same time with formula. Thank you for your comment.
  • To post as a guest, your comment is unpublished.
    Charley · 11 months ago
    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
  • To post as a guest, your comment is unpublished.
    Steve Parker · 1 years ago
    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.
    • To post as a guest, your comment is unpublished.
      Josh · 10 months ago
      Check your Calculating options. It needs to be set to automatic. File > Options > Formulas > Calculating options > Workbook Calculation (Automatic selection)
  • To post as a guest, your comment is unpublished.
    Matt · 1 years ago
    How would you add a second variable? For instance, I want all the unique elements in one column that also share a similar value in another column. In your example, imagine a 3rd column titled "Department" that would have values like product, meat, etc. I realize those are all Produce, but hopefully you get my point. Would you modify the CountIF formula to a COUNTIFS or do you modify it in another way?
    • To post as a guest, your comment is unpublished.
      crystal · 1 years ago
      Hi Matt
      Please try this formula =IF(ISNA(VLOOKUP(A2,$C$2:$C$13,1,FALSE)),"Yes","").
      Supposing the two compared lists are Column A and Column C, If the unique values stay only in Column A but not in Column C, it will be displayed Yes in column B; while if return nothing in Column B, it means corresponding value stays in both Column A and Column C.
      • To post as a guest, your comment is unpublished.
        jyotiba mali · 1 years ago
        Thanks for the reply.. but hot to pull out that unique value if it displayed YES.. could you please advice me the formula to pull the unique value in different column.
  • To post as a guest, your comment is unpublished.
    Zac · 1 years ago
    How would you add multiple criteria, such as if you only wanted to add to the dynamic list if the date was just 9/12?

    I'm trying "&" in the MATCH formula, but it's not working.

    For example, based on your example:
    =IFERROR(INDEX($B$2:$B$9, MATCH(0 & B4,COUNTIF($D$1:D1, $B$2:$B$9) & $A$2:$A$9, 0)),"")
    This throws an error or creates duplicates.

    Alternatively, I've read that "+" might work, although I can't get it working. Or using SMALL.

    Ideas?
  • To post as a guest, your comment is unpublished.
    Mike · 2 years ago
    Hi Crystal,
    I am trying to use the VB version of the unique values list and running into an issue.
    The range that I want to create a unique values column from is all formulas that refer to different tabs.
    How does one get the value to transfer over instead of the formula?
    • To post as a guest, your comment is unpublished.
      Odette Meintjes · 1 years ago
      I have the same problem, except that my formula refer to column names and cannot convert to absolute.
      How do I change the vba to paste the values and not the formula?
    • To post as a guest, your comment is unpublished.
      crystal · 1 years ago
      Dear Mike,
      Please convert your formula references to absolute, and then apply the VB script.
  • To post as a guest, your comment is unpublished.
    Jones · 2 years ago
    Any tips on getting the VBA option to work with Excel 2016 for macOS? I have followed the steps; however, when I run the macro, nothing happens at all. Thanks!
    • To post as a guest, your comment is unpublished.
      crystal · 2 years ago
      Daer Jones,
      Please try the below VBA code and let me know whether it works for you. Thank you!

      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
  • To post as a guest, your comment is unpublished.
    Ryan · 2 years ago
    Also, for whatever reason, the original formula provided:
    =IFERROR(INDEX($B$2:$B$9, MATCH(0,COUNTIF($D$1:D1, $B$2:$B$9), 0)),"")

    returns a "circular reference" warning and will not calculate..
    • To post as a guest, your comment is unpublished.
      Andrew · 1 years ago
      I've had this happen before - my fix was that I was entering the formula into the cell D1 (equivalent in the worksheet I was using). Whichever cell the $D:$1 corresponds to you need to be entering it in the cell below - D2. Apologies if that's not why you got the error
    • To post as a guest, your comment is unpublished.
      crystal · 2 years ago
      Dear Ryan,
      Which Office version do you use? The formula works well in my Office 2016 and 2013.
  • To post as a guest, your comment is unpublished.
    Ryan · 2 years ago
    Hello, and thank you for your help.

    I need exactly this functionality, but my list of "unique values" needs to extend across columns instead of rows, so the expanding list down the rows won't work for me.

    How can I modify this formula in order to make the "unique values" list expand as I drag it across the columns?

    Offset()?
    Transpose()?
    Indirect() with a string of absolute references concatenated with a reference to the column instead of row?


    Thanks again!
    • To post as a guest, your comment is unpublished.
      crystal · 2 years ago
      Dear Ryan,
      This formula =IFERROR(INDEX($B$2:$B$9, MATCH(0,COUNTIF($D$2:D2, $B$2:$B$9), 0)),"") + Ctrl + Shift + Enter can help you to solve the problem.
      See below screenshot:
  • To post as a guest, your comment is unpublished.
    Viswanath Urala · 2 years ago
    {=INDEX($Q$3:$Q$263,MATCH(0,COUNTIF(V$2:V2,$Q$3:$Q$263),0))} - found this to work from another site...

    Use the Ctrl+Shift+Enter to get the array function (curly braces). Drag copy-paste the formulas until the #NA is shown. My data set was in Column-Q, it was compared to see if it existed in the unique's list in Column-V, which continually stretches along this same column.
    • To post as a guest, your comment is unpublished.
      crystal · 2 years ago
      Good Day.
      Please list all unique values of column Q with the abobv formula, and then use his formula =IF(D2=V1,"Match","No match") to compare if the uniques in cilumn Q compareing to column V in the same row.
  • To post as a guest, your comment is unpublished.
    Outdated · 2 years ago
    This formula is outdated and doesn't work. I literally just set this exact excel sheet up to see if I could get this formula to work and it doesnt.
  • To post as a guest, your comment is unpublished.
    PJ · 2 years ago
    I am decent at excel but I am really trying to wrap my head around how and why the above formula works (it works for what I am using it for but I must understand why). I get a little confused using arrays sometimes so any explanation in idiots terms would be extremely helpful

    Regards
  • To post as a guest, your comment is unpublished.
    Eric · 2 years ago
    Thank you for the tutorial. Using the formula method, how would you alter the formula if you wanted to add a category qualifer? Say in column C you distinguish whether the item is a fruit or a vegetable. How would you change the code to only sort the unique fruits and exclude the vegetables? I tried replacing COUNTIF with COUNTIFS, using the second countifs criteria of (LIST RANGE,"CATEGORY") but it returns blank. Would I need to expand my array and incorporate VLOOKUP?