VLOOKUP()返回第1个非空或非0值

时间:2017-03-22 17:22:18

标签: excel vba excel-vba excel-formula excel-2013

我正在使用VLOOKUP()来返回值,但我遇到的问题是第一个值可能是NULL0

如何使用此功能(或类似功能)返回第一个 NON Null或0值?

Application.WorksheetFunction.VLookup(filterCon, Sheets("Ace Up Sleeve").Range("A:P"), 11, False)

1 个答案:

答案 0 :(得分:2)

我将使用AGGREGATE工作表函数在工作表上完成此操作。将其纳入VBA,您可以对同一公式使用Application.Evaluate(...)

Dim filterCon As String, fr As Variant, lr As Long, vreturn As Variant

filterCon = "findthis"

With Worksheets("Ace Up Sleeve")
    lr = .Cells(.Rows.Count, "A").End(xlUp).Row
    fr = Application.Evaluate("aggregate(15, 6, row(1:" & lr & ")/('Ace Up Sleeve'!K1:K" & lr & "<>0), 1)")
    If Not IsError(fr) Then
        vreturn = .Cells(fr, "K").Value
        Debug.Print vreturn
    End If
End With
相关问题