0
所以我試圖運行下面的代碼,但收到'類型不匹配錯誤'行ElseIf Cells(x, 1) <> "" And Cells(x, 2) <> "" And Cells(x, 15).Value <= 0 Then
。我猜這是關於if
沒有正確嵌套的語句在for
和next
語句中,但他們似乎都很好。我已經花了幾個小時在此嘗試調試,但無濟於事。誰能告訴我哪裏出了問題我的代碼?爲什麼我在運行elseif語句時收到類型不匹配錯誤
Dim x As Integer
For x = 4 To 100
If Cells(x, 1) <> "" And Cells(x, 2) <> "" And Cells(x, 6).Value <= 0 Then
Cells(x, 16).Value = 6
Cells(x, 17).Value = -0.3179688
ElseIf Cells(x, 1) <> "" And Cells(x, 2) <> "" And Cells(x, 15).Value <= 0 Then '(*Received error for this line)
Cells(x, 16).Value = 1
Cells(x, 17).Value = 0.6820312
ElseIf Cells(x, 5) = "" or Cells(x, 6) <> "" or Cells(x, 7) <> "" Then '(*Still Received error for this line)
Cells(x, 16).Value = ""
Cells(x, 17).Value = ""
ElseIf Cells(x, 1).Value = "A. Agriculture, forestry and fishing" Then
Select Case LCase(Cells(x, 2).Value)
Case "all", "id", "sg"
Select Case Cells(x, 15).Value
Case Is > 4
Cells(x, 16).Value = 5
Cells(x, 17).Value = -0.2405524
Case 2.01 To 4
Cells(x, 16).Value = 4
Cells(x, 17).Value = 0.0223717
Case 1.01 To 2
Cells(x, 16).Value = 3
Cells(x, 17).Value = 0.112231
Case 0.01 To 1
Cells(x, 16).Value = 2
Cells(x, 17).Value = 0.5928195
End Select
Case "my", "th"
Select Case Cells(x, 15).Value
Case Is > 4.5
Cells(x, 16).Value = 5
Cells(x, 17).Value = -0.2405524
Case 2.01 To 4.5
Cells(x, 16).Value = 4
Cells(x, 17).Value = 0.0223717
Case 1.01 To 2
Cells(x, 16).Value = 3
Cells(x, 17).Value = 0.112231
Case 0.01 To 1
Cells(x, 16).Value = 2
Cells(x, 17).Value = 0.5928195
End Select
Case ""
Cells(x, 16).Value = ""
Cells(x, 17).Value = ""
End Select
End if
Next x
End Sub
什麼在'Cells(x,15).Value'? – bernie
@Bernie,它在電子表格中包含一個現有公式'=(D4 + E4)F4'。 – tnkh
好的......那些細胞中有什麼?如果你有一個字符串,那麼檢查<= 0將會拋出一個類型錯誤。在進行比較之前,嘗試檢查它是否實際上是一個數字。 – user1274820