-1

这是委员会报告的一串代码。它每天运行良好,零问题,最后一次运行是在 13 日。

今天早上我收到一个Run Time Error 13 Type Mismatch.

我不知道为什么,但是当我调试时,它会突出显示此部分:

If UCase(Cells(i, 1).Value = "200265 - MP"然后

我试图重新输入它,但是当我这样做时,我得到一个错误的单词 Then 说明如下: Compile error: Expected: list seperator or )

我怎么能运行这个?

这是代码:

Sheets("Errors").Select
Cells.Select
Selection.Sort Key1:=Range("A2"), Order1:=xlDescending, Header:=xlGuess, _
    OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
    DataOption1:=xlSortNormal
Sheets("Errors").Select
With Sheets("Errors")
    lastrow = .Range("C" & Rows.Count).End(xlUp).Row
End With
For i = lastrow To 1 Step -1
    Cells(i, 1).Select
    If UCase(Cells(i, 1).Value = "200265 - MP" Then
        Rows(i).Select
        Selection.Cut
        Sheets("Temp").Select
        Rows("1:1").Select
        Selection.Insert Shift:=xlDown
        Sheets("Errors").Select
    End If
    If UCase(Cells(i, 1).Value) = "160850 - TP" Then
        Rows(i).Select
        Selection.Cut
        Sheets("Temp").Select
        Rows("1:1").Select
        Selection.Insert Shift:=xlDown
        Sheets("Errors").Select
    End If
    If UCase(Cells(i, 1).Value) = "170566 - VB" Then
        Rows(i).Select
        Selection.Cut
        Sheets("Temp").Select
        Rows("1:1").Select
        Selection.Insert Shift:=xlDown
        Sheets("Errors").Select
    End If
    If UCase(Cells(i, 1).Value) = "201447 - JB" Then
        Rows(i).Select
        Selection.Cut
        Sheets("Temp").Select
        Rows("1:1").Select
        Selection.Insert Shift:=xlDown
        Sheets("Errors").Select
    End If
    If UCase(Cells(i, 1).Value) = "202006 - BL" Then
        Rows(i).Select
        Selection.Cut
        Sheets("Temp").Select
        Rows("1:1").Select
        Selection.Insert Shift:=xlDown
        Sheets("Errors").Select
    End If
    If UCase(Cells(i, 1).Value) = "203646 - MM" Then
        Rows(i).Select
        Selection.Cut
        Sheets("Temp").Select
        Rows("1:1").Select
        Selection.Insert Shift:=xlDown
        Sheets("Errors").Select
    End If
    If UCase(Cells(i, 1).Value) = "203917 - KT" Then
        Rows(i).Select
        Selection.Cut
        Sheets("Temp").Select
        Rows("1:1").Select
        Selection.Insert Shift:=xlDown
        Sheets("Errors").Select
    End If
4

2 回答 2

1

你忘了关闭括号:写UCase(Cells(i, 1).Value) = "200265 - MP" Then

编辑:

很难,从评论中看是怎么回事。试一试:将此功能粘贴到您的模块中

Public Function myUCase(ByVal v As Variant) As String
    On Error GoTo error:

    myUCase = UCase(CStr(v))
    Exit Function

error:
    myUCase = ""

End Function

然后将您对 UCase 的调用替换为对 myUCase 的调用。

我在这里所做的是丢弃任何错误。

不过要谨慎使用它!

于 2013-06-17T13:04:10.757 回答
0

看起来你缺少一个括号

If UCase(Cells(i, 1).Value = "200265 - MP" Then

应该

If UCase(Cells(i, 1).Value) = "200265 - MP" Then
于 2013-06-17T13:04:42.117 回答