'双匹配查询,和VLookUp函数类似,不同的是可以匹配2个字段KeyCell匹配数据的第一列,MatchCell 匹配数据的第MatchIndex 列,如果2个都相等则返回数据区域第ReturnIndex列的值
'KeyCell:第一列匹配的单元格
'MatchCell:第二个匹配项目,匹配第MatchIndex列
'Zone :数据区域
'MatchIndex:第二项匹配的列序号
'ReturnIndex:返回值的列序号
Function VlookMatch(KeyCell As Range, MatchCell As Range, Zone As Range, MatchIndex As Integer, ReturnIndex As Integer)
Dim columnCount As Long, rowsCount As Long
Dim Key1 As String, Key2 As String
Dim i As Long, j As Integer
columnCount = Zone.Columns.Count
rowsCount = Zone.Rows.Count
If KeyCell.Cells.Count <> 1 Or MatchCell.Cells.Count <> 1 Then
VlookMatch = "#参数有误"
End If
If rowsCount < 2 Or columnCount < 1 Then
VlookMatch = "#数据区域至少2行,1列"
End If
If MatchIndex < 1 Or ReturnIndex < 1
Excel Vba 双匹配查询,类似Vlookup,能匹配2个关键字
最新推荐文章于 2024-12-23 12:14:13 发布