Sub AddLot()
Dim Wafers As Variant
Do
Wafers = InputBox("How many? 1 to 25")
If Wafers = "" Then Exit Sub
If IsNumeric(Wafers) Then
If Wafers >= 1 And Wafers <= 25 Then Exit Do
End If
Loop
End Sub
Hi Peter,Welcome to the MrExcel board!
When posting vba code in the forum please post your actual code not a picture of it. We cannot copy from a picture to test.
My signature block below has more information about posting code.
You have not shown how Wafersclick is given a value but whatever it is the yellow part below can never be true since Wafersclick cannot hold two different values at the same time.
Assuming that you want the user to able to exit the whole code with Cancel or no entry at all then perhaps something like this?
VBA Code:Sub AddLot() Dim Wafers As Variant Do Wafers = InputBox("How many? 1 to 25") If Wafers = "" Then Exit Sub If IsNumeric(Wafers) Then If Wafers >= 1 And Wafers <= 25 Then Exit Do End If Loop End Sub
Sub AddLot()
Dim Wafers As Variant
Do
Wafers = InputBox("How many Wafers will be processed:", "Inputs", "1 to 25")
If Wafers = "" Then Exit Sub
If IsNumeric(Wafers) Then
If Wafers <= 25 And Wafers >= 1 Then Exit Do
MsgBox "Please enter a valid number within 1 to 25"
End If
Loop
Do
End Sub
Sub WithoutLoop()
Dim strName As String
strName = InputBox(Prompt:="How many wafers will be produced?", Title:="Wafers", Default:="1 to 25")
If Not IsNumeric(strName) Then
Call WithoutLoop
Else
If strName < 1 Then
Call WithoutLoop
Else
If strName > 25 Then
Call WithoutLoop
Else
If IsNumeric(strName) Then
Worksheets("Sheet6").Range("a1").Value = strName
Else
If vbCancel Then
Exit Sub
End If
End If
End If
End If
End If
End Sub
Hello,Hi Peter,
Thank you for replying. Here comes another error, and it says that do without loop.
VBA Code:Sub AddLot() Dim Wafers As Variant Do Wafers = InputBox("How many Wafers will be processed:", "Inputs", "1 to 25") If Wafers = "" Then Exit Sub If IsNumeric(Wafers) Then If Wafers <= 25 And Wafers >= 1 Then Exit Do MsgBox "Please enter a valid number within 1 to 25" End If Loop [B][U][COLOR=rgb(226, 80, 65)]Do[/COLOR][/U][/B] End Sub