如何优化下面的VBA / Excel代码?

时间:2019-06-02 13:42:19

标签: vba

我正在尝试在单个单元格中进行多个vlookup。但是当前的代码非常慢并且需要很多时间。谁能建议如何优化此代码?

示例

Apples  A
B
C
Oranges D

预期结果

Apples A B C

我的代码

Function MYVLOOKUP(pValue As String, pWorkRng As Range, pIndex As Long)
    Dim rng As Range
    Dim xResult As String
    xResult = ""
    For Each rng In pWorkRng
        If rng = pValue Then
            xResult = xResult & " " & rng.Offset(0, pIndex - 1)
        End If
    Next
    MYVLOOKUP = xResult
End Function

没有错误,但我希望通过单个单元格中的值更快地执行vlookup

0 个答案:

没有答案