我爲一個文件創建了一個宏,首先它工作正常,但今天我一直打開並重新啓動文件和宏數百次,我總是得到出現以下錯誤:Excel VBA運行時錯誤'13'類型不匹配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. 非常感謝
這是百達數值介於0和3 – Diogo 2012-01-17 00:29:47
我在代碼的第一行,你給我的錯誤「編譯錯誤:語法錯誤」 – Diogo 2012-01-17 00:38:38
應該不會出現任何語法錯誤。確保你把它放在你的另一個'If'語句之後,並且你有所有的括號。 – 2012-01-17 00:47:08