[英]VBA Excel, mismatch for inputbox as integer
我的代碼
Dim a As Integer
a = InputBox("Enter the number", "Program", "", 7000, 6000)
If a = Empty Then
' do code...
Else
MsgBox "Enter the number."
End If
如果我留下一個空字段,Excel將返回Type Mismatch
錯誤。 我想顯示一條消息。
由於a
是Integer
,因此它不能包含String
或為Empty
。 使用Variant
然后檢查以查看返回的內容:
Dim a As Variant
Dim b As Integer
a = InputBox("Enter the number", "Program", "", 7000, 6000)
If Not IsNumeric(a) Then
'a is not a number
Else
'a is a number and can be converted to Integer
b = CInt(a)
End If
您有a
定義為Integer
。 Integer
不能為空。 使用Variant
而不是Integer
:
Dim a As Variant
a = InputBox("Enter the number", "Program", "", 7000, 6000)
If a = Empty Then
' do code...
Else
MsgBox "Enter the number."
End If
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.