Excel Vba 双匹配查询,类似Vlookup,能匹配2个关键字

'双匹配查询,和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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值