VBA运行时错误'13'类型不匹配

时间:2012-11-16 14:50:06

标签: excel-2010

我们最近使用Office 2010更新到Windows 7,现在我们的一些Excel宏无效。示例代码如下,我得到运行时错误'13'但无法找到类型不匹配的位置。

Private Sub btnUpdate_Click()

Dim lngLastRow As Long
Dim arrRevSource(0 To 9) As Long

Dim i As Integer

lngLastRow = Sheets("Test Log").Range("A1").End(xlDown).Row

For i = 2 To lngLastRow

If Sheets("Test Log").Cells(i, 7).Value <> "incl." And Sheets("Test Log").Cells(i,    7).Value <> "" And Sheets("Test Log").Cells(i, 7).Value <> "VOID" Then 'protect from  entries other than numbers

    Select Case Sheets("Test Log").Cells(i, 9).Value
        Case "A033", "A034", "A225", "A226" 'Cap2000
            arrRevSource(0) = arrRevSource(0) + Sheets("Test Log").Cells(i, 7).Value

          Case "0611", "0612", "0620", "0621", "0622", "0623", "0815", "0816", "0818", "0819", "0820", "0821" 'EVAP Development
            arrRevSource(1) = arrRevSource(1) + Sheets("Test Log").Cells(i, 7).Value

        Case "A084", "A173", "A220", "A224", "A290", "A294", "A301" 'Cert
            arrRevSource(2) = arrRevSource(2) + Sheets("Test Log").Cells(i, 7).Value

        Case "0792", "0794" 'Diesel In Use Enforcement
             arrRevSource(3) = arrRevSource(3) + Sheets("Test Log").Cells(i, 7).Value

        Case "0608", "0654" 'AMG
            arrRevSource(4) = arrRevSource(4) + Sheets("Test Log").Cells(i, 7).Value

        Case "0588" 'G Class Development
            arrRevSource(5) = arrRevSource(5) + Sheets("Test Log").Cells(i, 7).Value

          Case "0543", "0545", "0547", "0548", "A009", "A093", "A252", "A295", "A296" 'Third Party"

            arrRevSource(6) = arrRevSource(6) + Sheets("Test Log").Cells(i, 7).Value

       Case "A002", "A237" 'OBD
           arrRevSource(7) = arrRevSource(7) + Sheets("Test Log").Cells(i, 7).Value

       Case "A268" 'FETS
           arrRevSource(8) = arrRevSource(8) + Sheets("Test Log").Cells(i, 7).Value


           'For All Other Sources of Revenue
       Case "A074", "A109", "A168", "A185", "A199", "A208", "A217", "A239", "A270", "0666", "0669" 'Other
            arrRevSource(9) = arrRevSource(9) + Sheets("Test Log").Cells(i, 7).Value

        'Case Else 'Other
            'arrRevSource(9) = arrRevSource(9) + Sheets("Test Log").Cells(i, 7).Value


    End Select

End If

Next

For i = 1 To 10

    Sheets("Revenue Sources").Cells(3, i + 1).Value = arrRevSource(i - 1)

Next

End Sub

1 个答案:

答案 0 :(得分:1)

我不确定,如果这可以解决你所有的问题,但我肯定会改变它:

Dim i as integer 'should be as long!

For i = 2 To lngLastRow

我会说你对非数字的IF保护不起作用或者我误解了一些东西。您可能想尝试将此行用于您的选择:

Select Case CStr(Sheets("Test Log").Cells(i, 9).Value)