2014-01-23 83 views
-6

我有兩列數據。第一列是唯一整數值​​的列表。第二列是其中一些值重複的字符串值的列表。我想寫一個簡短的宏(或單元格公式),它將返回字符串旁邊的整數值。返回整數值下一個字符串值列表

Integers Strings Ideal Printout 
    0   Bob   0 
    1   Joe   1,2 
    2   Joe   1,2 
    3   Susan   3,5 
    4   Sally   4 
    5   Susan   3,5 

很抱歉,如果上面不明確。很難說清楚這一點。如果打印輸出是每個整數的列,我也很高興。

回答

0

這個工作對我來說:

Public Function GETMATCHES(ByVal match As String, ByVal cells As Range, ByVal columnOffset As Integer) As String 
    Dim result As String 
    Dim cell As Range 
    For Each cell In cells 
     If cell.Value2 = match Then 
      result = result & "," & cell.Offset(0, columnOffset).Value2 
     End If 
    Next 
    If Len(result) > 0 Then 
     result = Right(result, Len(result) - 1) 
    End If 
    GETMATCHES = result 
End Function 

我用這樣的:

=GETMATCHES(B2,$B$2:$B$7,-1) 
+0

你的先生是我的英雄。謝謝! – augusthippo

相關問題