2017-06-23 66 views
0

我需要查找數字(重複出現)並返回數字旁邊單元格的值,但僅限於同一日期。結果必須加入到同一個目標單元格中​​。Excel2011 - 查找並將多個值返回到一個單元格中按日期

我在Mac上使用Excel 2011。我沒有Textjoin函數。但是,我找到了一個VBA UDF來查找並將多個值返回到一個單元格中。這是我使用的是什麼:

Function MYVLOOKUP(pValue As String, pWorkRng As Range, pIndex As Long) 
'Update 20150310 
Dim rng As Range 
Dim xResult As String 
xResult = "" 
For Each rng In pWorkRng 
    If rng = pValue Then 
     xResult = xResult & " " & rng.Offset(0, pIndex - 1) 
    End If 
Next 
MYVLOOKUP = xResult 
End Function 

它種工作,但只有在一個小區仰視值和另一列找到它。問題是我正在查找的值在不同的日期重複,我只想返回給定日期的值。我已經把它貼的什麼,我想下面做一個樣本:

Sample Spreadsheet

通知書「所需數據格式」 G2被返回的數據職工1001數據庫中的兩個日期,但只有我希望它返回相關日期的數據,所以我試圖將myvlookup UDF中的第一個變量設置爲「E2:F2」,以便函數查找Date和Employee#,但該函數似乎不起作用那樣。

應顯示在G2的值是「80011,80025」,應該顯示在G3的值是「80011,80030」等

我希望我有更多的時間來想出解決辦法我自己,但時間是至關重要的,所以我需要幫助。

回答

1

這裏是模仿TEXTJOIN()一個UDF:

Function TEXTJOIN(delim As String, skipblank As Boolean, arr) 
    Dim d As Long 
    Dim c As Long 
    Dim arr2() 
    Dim t As Long, y As Long 
    t = -1 
    y = -1 
    If TypeName(arr) = "Range" Then 
     arr2 = arr.Value 
    Else 
     arr2 = arr 
    End If 
    On Error Resume Next 
    t = UBound(arr2, 2) 
    y = UBound(arr2, 1) 
    On Error GoTo 0 

    If t >= 0 And y >= 0 Then 
     For c = LBound(arr2, 1) To UBound(arr2, 1) 
      For d = LBound(arr2, 1) To UBound(arr2, 2) 
       If arr2(c, d) <> "" Or Not skipblank Then 
        TEXTJOIN = TEXTJOIN & arr2(c, d) & delim 
       End If 
      Next d 
     Next c 
    Else 
     For c = LBound(arr2) To UBound(arr2) 
      If arr2(c) <> "" Or Not skipblank Then 
       TEXTJOIN = TEXTJOIN & arr2(c) & delim 
      End If 
     Next c 
    End If 
    TEXTJOIN = Left(TEXTJOIN, Len(TEXTJOIN) - Len(delim)) 
End Function 

與您的數據,你會使用這個在數組公式:

=TEXTJOIN(" ",TRUE,IF((F2=B$2:B$14)*(A$2:A$14=E2),C$2:C$14,"")) 

作爲它需要被證實數組公式在退出編輯模式時,按Ctrl-Shift-Enter而不是Enter。如果正確完成,Excel將在公式周圍放置{}

相關問題