【问题标题】:Application.Match Run Time Error 13 in VBA MacroVBA 宏中的 Application.Match 运行时错误 13
【发布时间】:2015-03-03 06:06:36
【问题描述】:

此代码大约一个月前可以正常工作,没有任何问题。

运行时错误(#13)指向:

lastRow = Application.Match(campus, subject.Range("A1:A35000"), 1) + 2

我已经运行了几次宏,但有时它会部分成功。其他时候它根本没有得到任何数据。

如果宏部分成功,如果列中的数据始终相同,会导致类型不匹配。从 SQL Tools 导出的所有数据,然后复制并粘贴到工作表中。

Dim lastRow As Long
Dim firstRow As Long
Dim count As Long
Dim campus As String
Dim gradeCount As Integer
Dim current As String
Dim previous As String

campus = schools.Range("A" & i).Value
With subject.Range("A:A")
    Set Rng = .Find(what:=campus, _
                     After:=.Cells(.Cells.count), _
                     LookIn:=xlValues, _
                     LookAt:=xlWhole, _
                     searchorder:=xlByRows, _
                     searchdirection:=xlNext, _
                     MatchCase:=False)

    gradeCount = 0
    firstRow = 0
    If Not Rng Is Nothing Then
        firstRow = Application.Match(campus, subject.Range("A1:A35000"), 0) + 2
        lastRow = Application.Match(campus, subject.Range("A1:A35000"), 1) + 2
        gs.Range("A" & rowCount).Value = schools.Range("A" & i).Value
        gs.Range("C" & rowCount).Value = schools.Range("C" & i).Value
        currentCampus = gs.Range("A" & rowCount).Value
        current = ""
        previous = ""
        For count = firstRow To lastRow
            If campus = subject.Range("A" & count).Value Then
                current = subject.Range("C" & count)
                gs.Range("A" & rowCount).Value = schools.Range("A" & i).Value
                If current <> previous Then
                    gs.Range("C" & rowCount).Value = schools.Range("C" & i).Value
                    gs.Range("D" & rowCount).Value = grade
                    gs.Range("E" & rowCount).Value = current
                    previous = current
                    gradeCount = gradeCount + 1
                    rowCount = rowCount + 1
                End If
            End If
        Next count
        If gradeCount > 1 Then
            gs.Range("D" & rowCount).Value = grade
            gs.Range("E" & rowCount).Value = "*"
            gs.Range("C" & rowCount).Value = schools.Range("C" & i).Value
            rowCount = rowCount + 1
        End If
    End If
End With

【问题讨论】:

  • 您能否检查您的Range.Find 方法是否正确?似乎是从第一列的最后一个单元格开始搜索?

标签: vba excel


【解决方案1】:

这表明 Match 未能找到值。

如果相同的公式占用了工作表单元格,您会看到:

#N/A

【讨论】:

    猜你喜欢
    • 2021-10-30
    • 2014-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多