Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/25.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
Excel 为什么我使用MS文档中所示的语句将错误2042作为VBA匹配的结果_Excel_Vba_String_Match - Fatal编程技术网

Excel 为什么我使用MS文档中所示的语句将错误2042作为VBA匹配的结果

Excel 为什么我使用MS文档中所示的语句将错误2042作为VBA匹配的结果,excel,vba,string,match,Excel,Vba,String,Match,我有一张有两列(a+B)的低音表(TMP)。在A列中有数字作为字符串,在B列中有数字。现在,我尝试获取给定字符串的对应数字 我试过很多东西都准备好了,没什么用。据我所知,匹配语句的代码与MS文档中的代码相同。 我甚至对foreach循环也做了同样的操作,它工作得很好,但有点慢 Public Function SuchenKonto(Konto As String) As Boolean Dim ind As Variant Dim Rückgabe As Boolean

我有一张有两列(a+B)的低音表(TMP)。在A列中有数字作为字符串,在B列中有数字。现在,我尝试获取给定字符串的对应数字

我试过很多东西都准备好了,没什么用。据我所知,匹配语句的代码与MS文档中的代码相同。 我甚至对foreach循环也做了同样的操作,它工作得很好,但有点慢

Public Function SuchenKonto(Konto As String) As Boolean
    Dim ind As Variant
    Dim Rückgabe As Boolean
    Dim Vergl As Variant
    Vergl = Konto
    Rückgabe = False

    ind = Application.Match(Konto, Worksheets("TMP").Columns(1), 0)


    If Not IsError(ind) Then
        Rückgabe = True
        Worksheets("TMP").Range("B" & ind).Copy
        Sheets("Monatsvergleich").Range("AD1").Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, Transpose:=False
    End If
    SuchenKonto = Rückgabe

End Function

我该怎么做才能返回具有正确日期的行的索引?

似乎Match函数的第一个参数必须是单元格中的值。在使用Match函数的行之前添加以下行之后

表(“TMP”)。范围(“H1”)。单元格(1,1)。值=Konto

并将具有匹配函数的行更改为

ind=Application.Match(表格(“TMP”)。范围(“H1”)。单元格(1,1)。值,工作簿(m_WBKum)。工作表(“TMP”)。列(1,0)


它可以正常工作,不会出现进一步的错误。

函数用于获取结果,而不是复制和粘贴。你说“函数用于获取结果…”是什么意思。。。?我对IF块中的命令没有问题。我从匹配函数中得到错误。