0

我的最终目标是使用 VBA 中的用户定义函数来缩短这个公式,以下是我的参数 A1:C10、A1:A10、E1、B1:B10、F1(这会有所不同,这只是一个纯粹的例子)

Excel公式:

=index(A1:C10,match(1,(A1:A10=E1)*(B1:B10=F1),0),G1)

使用用户定义的函数,它会是这样的:

=pick(A1:C10, A1:A10, E1, B1:B10, F1, G1)

我的 VBA 代码是这样的,但是,它不起作用。请高手,帮帮我。非常感谢。

Function pick(range As range, con1 As range, con1a As range, con2 As range, con2a As range, col As range) As Variant

pick = WorksheetFunction.Index(range, Match(1, (con1 = con1a) * (con2 = con2a), 0), col)

End Function
4

1 回答 1

0

使用评估方法:

Function pick(range As range, con1 As range, con1a As range, con2 As range, con2a As range, col As range) As Variant

pick = Application.Caller.Parent.Evaluate("Index(" & range.Address(1,1,,1) & ",Match(1, (" & con1.Address(1,1,,1) & " = " & con1a.Address(1,1,,1) & ") * (" & con2.Address(1,1,,1) & " = " & con2a.Address(1,1,,1) & "), 0), " & col.Address(1,1,,1) & ")")

End Function
于 2017-12-24T17:47:21.670 回答