满足两列条件的数据引用,如果需要像Vlookup函数一样,取符合条件的指定列结果时,需要自定一个函数VlookupW,代码在下面,函数使用方法是=VlookupW(条件1,条件2,数据区域,结果列,是否精确匹配):
Function VlookupW(s1, s2, s3, s4, s5)
If s3(s3.Count).Column - s3(1).Column + 1 < 2 Then
VlookupW = "区域太小"
Exit Function
End If
If s3(s3.Count).Column - s3(1).Column + 1 < s4 Then
VlookupW = "区域小于显示列"
Exit Function
End If
For i = 1 To s3(s3.Count).Row - s3(1).Row + 1
If s5 <> 0 Then
If s3(i, 1) & s3(i, 2) = s1 & s2 Then
VlookupW = s3(i, s4)
Exit Function
End If
Else
If InStr(s3(i, 1), s1) And InStr(s3(i, 2), s2) Then
VlookupW = s3(i, s4)
Exit Function
End If
End If
Next
End Function