从索引值中减去

时间:2018-03-08 05:54:59

标签: excel vba excel-vba

这是我在这里发布的第一个问题...... 我坚持减去索引值。我已经给出了以下代码......

Sub index()
Dim var As Variant
Dim var1 As Variant

var = Application.WorksheetFunction.index(Worksheets("Stocks").Range("D:E"),  _
    Application.WorksheetFunction.Match(Worksheets("Invoice").Range("B12").Value,  _
    Worksheets("Stocks").Range("B:B"), 0), 2)
var1 = Worksheets("Invoice").Range("C12").Value

var.Value = var - var1
End Sub

2 个答案:

答案 0 :(得分:1)

试一试,

Sub index()

    dim rw as variant
    Dim var As Variant
    Dim var1 As Variant

    rw = Application.Match(Worksheets("Invoice").Range("B12").Value, Worksheets("Stocks").Range("B:B"), 0)
    if not iserror(rw) then
        var = Worksheets("Stocks").cells(rw, "E").value2
        var1 = Worksheets("Invoice").Range("C12").Value2
        var = var - var1
        debug.print var
    else
        debug.print "no match for " & Worksheets("Invoice").Range("B12").Value
    end if
End Sub

答案 1 :(得分:0)

这对我有用......

WebBrowser