【问题标题】:Fix IsNumeric Loop Bug?修复 IsNumeric 循环错误?
【发布时间】:2015-06-04 17:01:38
【问题描述】:

我正在尝试修复一个简单的循环,以便在用户输入整数之前消息框不会消失。 这是我的代码:

Sub PlateMicro()

strName = InputBox(Prompt:="Enter number of wells in plate. The default is 96 (8X12).", _
      Title:="PLATE SETUP", Default:="96")

Dim wellCount As Object
Dim numericCheck As Boolean
numericCheck = IsNumeric(wellCount)

If IsNumeric(wellCount) Then
Range("A1").Value = wellCount 'Enter the number of plate wells selected into template.
Else: strName = InputBox(Prompt:="You must enter an integer. Enter number of wells in plate. The default is 96 (8X12)." _
      , Title:="PLATE SETUP", Default:=userDefaultChoice)
End If
End Sub

【问题讨论】:

  • 我尝试了一个“If”循环,我该如何做这个循环?我这几天学习了VBA,我还是个初学者。
  • If 是一个条件结构......它不会循环。如果你在想“GoTo”,那你就错了……在 VBA 中实现循环的方式大约有 6-7 种不同的方式,只需选择一种即可。

标签: excel vba loops isnumeric


【解决方案1】:

考虑:

Sub intCHECK()
   Dim var As Variant
   var = "whatever"
   While Not IsNumeric(var)
      var = Application.InputBox(Prompt:="Enter integer", Type:=2)
   Wend

   MsgBox "Thanks!"
End Sub

如果您触摸取消

,这将允许您退出

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-03
    • 2023-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多