Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 从索引值中减去_Vba_Excel - Fatal编程技术网

Vba 从索引值中减去

Vba 从索引值中减去,vba,excel,Vba,Excel,这是我在这里发布的第一个问题。。。 我一直在努力减去索引值。我已经给出了下面的代码 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").V

这是我在这里发布的第一个问题。。。 我一直在努力减去索引值。我已经给出了下面的代码

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
试试看

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
这对我有用

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

Set 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

您是否收到任何错误?我可以通过快速扫描告诉您,您不需要
var.Value
中的
值。。非常感谢您的及时回复……但是它不起作用,但是……在研究过程中,我通过在var之前使用“Set”函数找到了另一种方法,它起作用了……:)下面…让我给出对我有用的代码。。。