Excel类型mistmach 13
我的代码有问题Excel类型mistmach 13,excel,vba,Excel,Vba,我的代码有问题 Sub SumZisk() Dim suma As Integer For i = 1 To 20 Set curCell = Cells(i, 3) suma = suma + curCell.Value Next i Range("C21").Value = suma End Sub 错误:类型mistmach 13 谢谢你的回答:)这对我很有效。尝试将此选项与显式选项一起使用 Option Expl
Sub SumZisk()
Dim suma As Integer
For i = 1 To 20
Set curCell = Cells(i, 3)
suma = suma + curCell.Value
Next i
Range("C21").Value = suma
End Sub
错误:类型mistmach 13
谢谢你的回答:)这对我很有效。尝试将此选项与显式
选项一起使用
Option Explicit
Sub SumZisk()
Dim suma As Integer
Dim i As Integer
Dim curCell As Range
For i = 1 To 20
Set curCell = Cells(i, 3)
suma = suma + curCell.Value
Next i
Range("C21").Value = suma
End Sub
哪一行有错误?我的猜测是,范围中的一个单元格不包含整数,但是没有办法确定,因为您没有费心说出范围包含的内容。另外--您确实应该使用选项Explicit
,而不是使用所有这些隐式声明的变量。@JohnColeman行号:7@Dort你的编号系统模棱两可。对我来说,第7行是下一行。还有,你试过我们的修复方法了吗?他们成功了吗?一般来说,你应该告诉你的回答者什么是有效的,什么是无效的。虽然选项Explicit
很好,但这段代码可能会在同一行中出现完全相同的类型错误。问题不在于代码,而在于代码和范围之间的交互。关于CInt(),您是正确的。我删除了我的答案。@johncolman关于CInt()
你是对的。上面的代码对我有用。目前的问题无法回答。很明显,curCell.Value
(对于至少一个i
)包含一个无法转换为整数的值——但OP没有给出任何关于这些值的线索。@JohnColeman我同意你的看法。我的回答假设它们都是整数,或者可以隐式转换为这样的整数。OP确实需要提供更多关于他的价值观的信息。谢谢