![](/img/trans.png)
[英]Is there a way to scan an entire column based on one cell in another column and pull out a value of the corresponding column?
[英]How to get every value from one column to another column based on its corresponding value
正如您在圖像中看到的那樣,“ Col B”多次具有相同的數字。 例如:“ 1”是四倍,“ 2”是三倍,依此類推。 但是,所有這些數字都對應於“ Col A”中的特定數字。 我想做的是獲取以橙色和黃色突出顯示的列。 您可以清楚地看到我做了什么。 我需要的是一個為我完成的excel函數。 這只是一個示例。 我的數據集中有數百萬個數據點,我無法輸入所有內容。
謝謝!!
單元格E2
公式
=IFERROR(SMALL(IF($B:$B=$D2,ROW($B:$B)-1),COLUMN(A:A)),"")
輸入為數組公式(使用Ctrl-Shift-Enter而不是Enter來輸入)
復制任意數量的單元格
注意:此公式相當慢。 設計良好的UDF將更快。
使用UDF解決此問題的一種方法是
Function MultiLookup(Val As Variant, rItems As Range, rLookup As Range, Index As Long) As Variant
Dim vItems As Variant
Dim i As Long, n As Long
With rItems
If IsEmpty(.Cells(.Count)) Then
Set rItems = Range(.Cells(1, 1), .Cells(.Count).End(xlUp))
End If
End With
vItems = rItems
n = 0
For i = 1 To UBound(vItems, 1)
If vItems(i, 1) = Val Then
n = n + 1
If n = Index Then
MultiLookup = rLookup.Cells(i, 1)
Exit Function
End If
End If
Next
MultiLookup = vbNullString
End Function
像這樣使用,用於單元格E2
=MultiLookup($D2,$B:$B,$A:$A,COLUMN(A:A))
同樣,根據需要復制整個單元格
這是另一個非UDF解決方案,可以快速運行。 請注意,它使用AGGREGATE
-Function,僅自Excel-2010起可用。
將其放入E2並拖動。
=INDEX($A$2:$A$1000,AGGREGATE(15,6,Row($1:$1000)/($B$2:$B$1000=$D2),COLUMN(A:A)))
您也可以使用IFERROR
包裹此公式,以確保您不會獲得#VALUE!
錯誤。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.