即使有错误处理,也无法获取工作表函数 class 的 vlookup 属性

Unable to get the vlookup property of the worksheetfunction class even with error handling

Sub storage_data()
'declare range

Dim res As Variant
Dim dw As Variant
Set Rng = Sheet16.Range("G17:H46") 'product name in H col and quantity in G col

' to deduct from storage
For s = 3 To 30

    On Error Resume Next
    'all the product's name in B col and storage quantity in L col of sheet14
    
        res = Application.WorksheetFunction.VLookup(Sheet14.Range("B" & s).Value, Rng, 1, False)
        'FYI I tried just "Application.VLookup(Sheet14.Range("B" & s).Value, Rng, 1, False)" too
        dw = Sheet14.Range("L" & s).Value
        dw = dw - res
        
    If Err.Number <> 0 Then
    End If
    On Error GoTo 0
Next

End Sub

使用Application.Match

查找
Option Explicit

Sub storage_data()
    
    Dim srg As Range: Set srg = Sheet16.Range("G17:H46")
    Dim cIndex As Variant
    
    With Sheet14
        For s = 3 To 30
            cIndex = Application.Match(.Range("B" & s).Value, srg.Columns(1), 0)
            If IsNumeric(cIndex) Then
                On Error Resume Next
                .Range("L" & s).Value = .Range("L" & s).Value _
                    - srg.Columns(2).Cells(cIndex)
                On Error GoTo 0
            End If
        Next
    End With

End Sub