我有一个excel公式,我经常用它来做VLookup
。它有一个嵌入式Index/Match
,它给出“M”列中的最后一个数值。
工作表式是这样的:在Excel中使用索引和匹配VBA VLookup函数
=VLOOKUP(INDEX($M$10:$M75,MATCH(9.99999999999999E+307,$M$10:$M75)),Data,4)
细胞$M75
是所述行这个公式中的细胞有数字,非数字和空白细胞在M列,但ID的,我想是总是数字。 。
所以我想写一个自定义的功能,它可以让我简单地写=current()
以下是我有:
Function Current()
Dim LookupRange As Variant
Dim indexVar As Variant
LookupRange = Range("$M$1:M" & ActiveCell.Row)
indexVar = Application.Index(Range(LookupRange), Application.Match(9.99999999999999E+307, Range(LookupRange)))
Current = Application.WorksheetFunction.VLookup(indexVar, Worksheets("Info").Range("Data"), 4)
End Function
我一直在使用不同的变量类型(字符串,长,变尝试)但我似乎无法获得该功能的工作。
我不知道这是否足够的信息,但任何人都可以看到我是否失去了一些东西?
我只得到#VALUE!
使用Excel 2013在Windows 7
在进入VBA之前,你的excel函数返回正确的结果吗? – sam092
单步执行代码并确定** 1)**是分配给“LookupRange”的值是否正确? ** 2)**是否正确指定给'indexVar'的值? –
@ sam092 - 我的原始公式正确运行。 – Brad