我有一個宏,它將特定的值添加到特定的字符串。然而,我目前正在得到一個運行時錯誤,我不明白爲什麼?運行時錯誤 - 類型不匹配
Case "L"
If UCase(Left(Dn, 3)) = "L/M" Then
Dn.Offset(, 1) = Val(Mid(Dn, 4, 2)) + 35
ElseIf UCase(Left(Dn, 2)) = "LM" Then
'Dn.Offset(, 1) = Val(Mid(Dn, 3, 3)) + 3.5
If IsNumeric(Mid(Dn, 3, 1)) And IsNumeric(Mid(Dn, 4, 1)) Then
If Mid(Dn, 4, 1) = "0" Then
Dn.Offset(, 1) = Mid(Dn, 3, 2) + 3.5
Else
Dn.Offset(, 1) = Mid(Dn, 3, 2) + 0.35
End If
End If
If IsNumeric(Mid(Dn, 4, 1)) And IsNumeric(Mid(Dn, 5, 1)) Then
If Mid(Dn, 5, 1) = "0" Then
Dn.Offset(, 1) = Mid(Dn, 3, 3) + 35
Else
Dn.Offset(, 1) = Mid(Dn, 3, 3) + 0.35
End If
End If
ElseIf UCase(Left(Dn, 3)) = "LOW" Then
Dn.Offset(, 1) = Val(Mid(Dn, 4, 2)) + 20
ElseIf UCase(Left(Dn, 3)) = "LO-" Then
Dn.Offset(, 1) = Val(Mid(Dn, 4, 2)) + 20
ElseIf UCase(Left(Dn, 6)) = "LO MID" Then
Dn.Offset(, 1) = Val(Mid(Dn, 7, 3)) + 35
ElseIf UCase(Left(Dn, 2)) = "L+" Then
Dn.Offset(, 1) = Num
ElseIf UCase(Left(Dn, 3)) = "LO " Then
Dn.Offset(, 1) = Val(Mid(Dn, 4, 2)) + 20
'ElseIf UCase(Left(Dn, 1)) = "L" Then
'Dn.Offset(, 1) = Val(Mid(Dn, 2, 3)) + 2
'ElseIf IsNumeric(Mid(Dn, 2, 1)) Then
'Dn.Offset(, 1) = IIf(IsNumeric(Mid(Dn, 2, 1) + Mid(Dn, 3, 1)), Val(Mid(Dn, 2, 3)) + 2, Val(Mid(Dn, 2, 1)) + 0.2)
ElseIf IsNumeric(Mid(Dn, 2, 1)) And IsNumeric(Mid(Dn, 3, 1)) Then
If Mid(Dn, 3, 1) = "0" Then
Dn.Offset(, 1) = Mid(Dn, 2, 2) + 2
Else
Dn.Offset(, 1) = Mid(Dn, 2, 2) + 0.2
End If
Else
Dn.Offset(, 1) = Val(Mid(Dn, 2, 3)) + 20
End If
If IsNumeric(Mid(Dn, 3, 1)) And IsNumeric(Mid(Dn, 4, 1)) Then
If Mid(Dn, 4, 1) = "0" Then
Dn.Offset(, 1) = Mid(Dn, 2, 3) + 20
Else
Dn.Offset(, 1) = Mid(Dn, 2, 3) + 0.2
End If
End If
輸入數據
*vh105 --> 105.9
*h107 --> 107.8
*l107 --> 107.2
*lm106 --> 106.35
*lm106
*l107
*44
這個問題的任何幫助將是非常可以理解的。
使用該步驟進入(Debug> Step Into)來調試並查看代碼實際停止工作的哪一行。同時打開當地人的觀看窗口(視圖>當地人觀看),看看是否所有的價值都是根據您的期望 –
非常感謝您的答覆,但第三行代碼有問題。另外,我的本地監視變量沒有顯示任何內容。對於「情況M」,我有相同的代碼,「MH」和M變量的代碼相同,所以在運行時不會出現錯誤類型錯誤。 – user1574185
當地人觀看將顯示本地元素的值或對象分配。所以我期望Dn被顯示在那裏,因爲它看起來像是一個'string'類型的局部變量。 –