2016-08-08 77 views
0

是否有从vlookup返回多个值的方法?我希望工作表1中的col I将多个值返回给单元格,还是有另一种显示方式(宁可不透视)?Vlookup,将多个值返回给单元格

表1:具有所有我的唯一值(西F和在Ⅰ型胶原返回值),

表3:柱A具有对应于在色柱B唯一的字符串的重复字符串值,其是独一无二的,包括空白。

EDIT

表1或期望的结果

enter image description here

表1:当前

enter image description here

表3当前

enter image description here

电流式

=VLOOKUP(F2,Sheet3!A:B,2,FALSE) 

返回大多0时,由于对应于该唯一值的坯料或多个值。

+0

你可以把照片?无法从你的描述中得到什么* Sheet3 Column B *和* Sheet1 Column F *。 –

+0

嗨蒂姆,这有帮助吗? – Jonnyboi

+0

这有助于我现在明白你的想法。我想我已经看到它在网站上的其他地方完成,但我不记得在哪里。我不认为它使用'VLOOKUP',但绝对是一个数组公式。 –

回答

1

就VBA而言,您必须稍微更改我向您发送的链接中的代码。这应该工作:

Option Explicit 
Function vlookupmulti(rngLookup As Variant, rngSource As Range, col As Double) As String 
Dim d As Double, strCell As String 

'Error if range has less columns than col 
If rngSource.Columns.Count < col Then 
    vlookupmulti = CVErr(xlErrNA) 
    Exit Function 
End If 

'Loop through rows in the lookup column 
For d = rngSource.Row To rngSource.Rows.Count 
    If rngLookup = Sheets(rngSource.Parent.Name).Cells(d, rngSource.Column).Value Then 
     strCell = Sheets(rngSource.Parent.Name).Cells(d, rngSource.Column + col - 1).Value 
     If Len(strCell) > 0 Then vlookupmulti = vlookupmulti & strCell & ", " 
    End If 
Next d 

'Remove comma at end 
If Right(vlookupmulti, 2) = ", " Then 
    vlookupmulti = Left(vlookupmulti, Len(vlookupmulti) - 2) 
End If 

'Give error if no results 
If vlookupmulti = "" Then 
    vlookupmulti = CVErr(xlErrNA) 
End If 

End Function 
+0

感谢您的回复Tim,我如何在工作表格式化公式?即'vlookupmulti =(lookup value,___,__)' – Jonnyboi

+0

和普通的VLOOKUP一样,但我没有得到最后一个TRUE/FALSE参数。 –

+0

它的工作原理:),无论如何,它使运行速度更快?似乎冻结我的优秀。 – Jonnyboi

相关问题