1

我们最近使用 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
4

1 回答 1

1

我不确定这是否能解决你所有的问题,但我肯定会改变它:

Dim i as integer 'should be as long!

For i = 2 To lngLastRow

我会说你的 IF-Protection against non-numbers 不能正常工作,或者我误解了一些东西。您可能想尝试使用此行进行选择:

Select Case CStr(Sheets("Test Log").Cells(i, 9).Value)
于 2012-11-16T19:27:25.873 回答