乔山办公网我们一直在努力
您的位置:乔山办公网 > excel表格制作 > 如何在VBA中判断文本框输入的是否是数字

如何在VBA中判断文本框输入的是否是数字

作者:乔山办公网日期:

返回目录:excel表格制作


DIM a As Integer
a=0

If range("E1")=2
a=a+10
end if

If range("E2")=2
a=a+10
end if

If range("E3")=4
a=a+10
end if

If range("E4")=2
a=a+10
end if
MsgBox "得分:"&a

81个textbox 弄成控件zhidao数组textbox(),然后
for i=0 to 79
    if not IsNumeric(textbox(i).text) then
        msgbox "第" & i & ”个textbox框输入非数字"
        exit for
    end if
next

以A1单元zhidao格为样
Application.IsText(Cells(1, 1)) = True "文本"
IsNumeric(Cells(1, 1)) = True "数值"
IsDate(Cells(1, 1)) = True "日期"

这里假设你的那个按钮的名字叫Button,然后把下面的代码放进去就可以了(已测试!

Private Sub Button_Click()
Dim i As Variant
i = InputBox("请输入一个数字", "数字录入中", 1)
If IsNumeric(i) = False Then
MsgBox "你输入的不是数值,请重新输入", , "输入错误!"
i = InputBox("请输入一个数字", "数字录入中", 1)
End If
End Sub

相关阅读

关键词不能为空
极力推荐

ppt怎么做_excel表格制作_office365_word文档_365办公网