我为一个文件创建了一个宏,一开始它运行良好,但今天我已经打开和重新启动文件和宏数百次,每次都会出现以下错误:
Excel VBA 运行时错误 '13' 类型不匹配
我没有改变宏中的任何内容,也不知道为什么会出现这个错误。此外,每次运行宏需要更新大约9000行数据,这需要很长时间。
错误在 ** ** 之间的行上。
VBA:
Sub k()
Dim x As Integer, i As Integer, a As Integer
Dim name As String
name = InputBox("Please insert the name of the sheet")
i = 1
Sheets(name).Cells(4, 58) = Sheets(name).Cells(4, 57)
x = Sheets(name).Cells(4, 57).Value
Do While Not IsEmpty(Sheets(name).Cells(i + 4, 57))
a = 0
If Sheets(name).Cells(4 + i, 57) <> x Then
If Sheets(name).Cells(4 + i, 57) <> 0 Then
If Sheets(name).Cells(4 + i, 57) = 3 Then
a = x
Sheets(name).Cells(4 + i, 58) = Sheets(name).Cells(4 + i, 57) - x
x = Cells(4 + i, 57) - x
End If
**Sheets(name).Cells(4 + i, 58) = Sheets(name).Cells(4 + i, 57) - a**
x = Sheets(name).Cells(4 + i, 57) - a
Else
Cells(4 + i, 58) = ""
End If
Else
Cells(4 + i, 58) = ""
End If
i = i + 1
Loop
End Sub
我在Windows 7上使用Excel 2010。
="3"
而不是= 3
。 - csandreas1