VBA Excel,输入框不匹配为整数 [英] VBA Excel, mismatch for inputbox as integer

查看:130
本文介绍了VBA Excel,输入框不匹配为整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码

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返回一个类型不匹配错误。我想显示一条消息。

If I leave an empty field , Excel returns a Type Mismatch error. I would like to display a message.

推荐答案

由于 a 整数,它不能包含 String 。使用变式,然后检查以查看已返回的内容:

Since a is an Integer, it cannot contain a String or be Empty. Use a Variant and then check to see what has been returned:

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

这篇关于VBA Excel,输入框不匹配为整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆