2016-08-14 44 views
0

我需要VLOOKUP與單元格A1 Sheet 1中的列A,A2值在單個小區中查找多個值(用逗號分隔),然後將值返回到一個單電池(也以逗號分隔)

SD-121, SD-232, SD-23 
SD-323,SD-333 

等..在不同的片材與列A VLOOKUP表,B,C,D柱A具有

A   B 
SD-232  US 
SD-23  UK 
SD-323  IN 
SD-333  SG 
SD-121  CN 

查找結果是要被顯示在Sheet的B欄導致細胞B1和B2

B 
CN, US, UK 
IN, SG 
+0

從你的問題中不清楚你想達到什麼。試着提供一個例子和預期的結果,所以其他人會理解你。 – tarashypka

+0

@tarashpka檢查是否有幫助 – rockedbyjava

回答

0

你可以通過VLOOKUP函數創建一個用戶函數循環值:

Function VLOOKUPARRAY(ByVal lookup_val As Range, ByVal table_array As Range, ByVal col_index_num As Integer, Optional ByVal range_lookup As Integer = 0) As String 
    Dim s As String 
    Dim a1() As String 
    Dim a2() As Variant 
    Dim i As Integer 

    'Recalculate whenever a calculation happens on the worksheet 
    Application.Volatile 

    'Get the lookup value from the cell 
    s = lookup_val.Value 
    'Split into array 
    a1 = Split(s, ",") 
    'Set output array to input array dimensions 
    ReDim a2(0 To UBound(a1)) 
    'Loop through input array and set output array elements to lookup results using application lookup function. 
    For i = 0 To UBound(a1) 
     a2(i) = Application.WorksheetFunction.VLookup(Trim(a1(i)), table_array, col_index_num, range_lookup) 
    Next i 
    'Loop through output array and load values into a string 
    s = "" 
    For i = 0 To UBound(a2) 
     s = s & a2(i) & ", " 
    Next i 
    'Knock the final ", " off the end of the string 
    s = Left(s, Len(s) - Len(", ")) 
    'Set function output to string value. 
    VLOOKUPARRAY = s 
End Function 

這是快速和骯髒的,但它給了我所需的輸出。根據需要調整。

+0

感謝您的回覆 – rockedbyjava

+0

不客氣。希望它解決了。 – JMcD

0

如果從2016年2月的Office 365最新更新,那麼你可以使用下面的數組公式:

=TEXTJOIN(",",TRUE,IF(ISNUMBER(SEARCH(Sheet2!$A$1:$A$5,A1)),Sheet2!$B$1:$B$5,"")) 

是數組公式,它必須與確認按Ctrl-Shift鍵輸入,而不是進入退出編輯時模式。如果做得正確,Excel將在公式周圍放置{}

返回將按照表2中的列表順序排列,而不是逗號分隔字符串的順序。

enter image description here

+0

我沒有最新的辦公室365.仍然感謝您的迴應 – rockedbyjava