[英]I get type mismatch error in for loop in VBA
'find the total of ages and anticor level to find the average For i = 1 To lastCellNumber totalAge = totalAge + Cells(i, 4) totalAnticorLevel = totalAnticorLevel + Cells(i, 6) Next i
使用 FunThomas 的建议:
'find the total of ages and anticor level to find the average
For i = 1 To lastCellNumber
if IsNumeric(Cells(i, 4).value) as sNumeric(totalAge) then
totalAge = totalAge + Cells(i, 4)
end if
if IsNumeirc(totalAnticorLevel) and IsNumeric(Cells(i, 6).value) then
totalAnticorLevel = totalAnticorLevel + Cells(i, 6)
end if
Next i
但这不会计算其中一个地块不是数字的情况,这将是您要解决的下一个问题。
当你这样做
totalAge + Cells(i, 4)
您正在使用 CELL( Cells(i, 4)
)添加一个值( totalAge
)。 您需要使用单元格的值,例如:
totalAge + Cells(i, 4).value
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.