1

I am trying to fix a simple loop so that the message box won't go away until the user enters an integer. Here is my code:

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
  • I tried to have an "If" loop, how do I made this a loop?I have learned VBA in the last couple days, I'm still a beginner. –  Jun 04 '15 at 17:08
  • 1
    `If` is a conditional structure... it doesn't loop. And if you're thinking "GoTo", you're doing it wrong... there's about 6-7 different ways of implementing a loop in VBA, just pick one. – Mathieu Guindon Jun 04 '15 at 17:10

1 Answers1

0

Consider:

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

This will allow you to Exit if you touch Cancel

Gary's Student
  • 95,722
  • 10
  • 59
  • 99