[英]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.