[英]I cannot make this code work, it is a “type mismatch error”
这段代码有什么问题吗? 我需要查看一列,如果该值小于参考值(它是一个计时器),则需要复制相邻的单元格并放入“ A8”中。
谢谢。
Sub GetData()
Dim i As Integer
For i = 4 To 31
If Cells(i, 38) < Cells(32, 5) Then
Cells(1, 8) = Cells(i, 39)
End If
Next i
End Sub
或者,在所有提供的选项中,在现有的if
之前添加此附加的If statement
:
If IsError(Cells(i, 39)) = False And IsError(Cells(32, 5))= False Then
您可以尝试在单元格中测试数字值,然后再测试小于以下值:
Sub GetData()
Dim i As Integer
For i = 4 To 31
if isnumeric(cells(i,38)) then
If Cells(i, 38) < Cells(32, 5) Then
Cells(1, 8) = Cells(i, 39)
' Exit For ' UN-COMMENT to exit loop
End If
else
msgbox "Cell '" & cells(i,38).address & "' may have an error",vbexclamation+vbokonly
end if
Next
End Sub
顺便说一句,David和Kazjaw的上述评论是正确的,循环的每次迭代都可能会覆盖A8单元!
测试一旦返回true,您可以退出循环,如下所示:
Exit for
为了避免不匹配,请尝试与单元格的文本进行比较:
If Cells(i,38).Text < Cells(32,5)...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.