【发布时间】:2012-01-16 19:52:19
【问题描述】:
我为一个文件创建了一个宏,首先它工作正常,但今天我已经打开并重新启动文件和宏数百次,我总是收到以下错误:
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。
【问题讨论】:
-
可能您正在执行 if 语句并比较字符串而不使用双引号。使用
="3"而不是= 3
标签: excel excel-2010 vba