DeepUnderground
07-19-2010, 02:08 PM
I have the following VBA Code:
Option Explicit
Sub mySheetFormat()
Dim i As Variant
Dim MinSheets As Integer, MaxSheets As Integer
Dim myTitle As String, myPrompt As String
Dim myFlag As Boolean
MinSheets = 1
MaxSheets = 5
myTitle = "# of Sheets"
myPrompt = "Input the Number of Worksheets."
Do
myFlag = False
On Error Resume Next
i = Application.InputBox(Prompt:=myPrompt, Title:=myTitle)
If i = False Then
Exit Do
ElseIf Not (i) = CInt(i) Then
myFlag = True
End If
myTitle = "Warning!!!"
myPrompt = "Workheets Must Be An Integer Between " & Str(MinSheets) & " and " & Str(MaxSheets) & "."
Loop Until i >= MinSheets And i <= MaxSheets And myFlag = False
End Sub
It works fine, except when the user inputs 0 into the input box. The code things that 0=false and it exits the loop. If the user inputs 0 and selects "ok", it should go back into the do loop. Anyone have any ideas?
Please use the code tags when posting code. Thank you.
Option Explicit
Sub mySheetFormat()
Dim i As Variant
Dim MinSheets As Integer, MaxSheets As Integer
Dim myTitle As String, myPrompt As String
Dim myFlag As Boolean
MinSheets = 1
MaxSheets = 5
myTitle = "# of Sheets"
myPrompt = "Input the Number of Worksheets."
Do
myFlag = False
On Error Resume Next
i = Application.InputBox(Prompt:=myPrompt, Title:=myTitle)
If i = False Then
Exit Do
ElseIf Not (i) = CInt(i) Then
myFlag = True
End If
myTitle = "Warning!!!"
myPrompt = "Workheets Must Be An Integer Between " & Str(MinSheets) & " and " & Str(MaxSheets) & "."
Loop Until i >= MinSheets And i <= MaxSheets And myFlag = False
End Sub
It works fine, except when the user inputs 0 into the input box. The code things that 0=false and it exits the loop. If the user inputs 0 and selects "ok", it should go back into the do loop. Anyone have any ideas?
Please use the code tags when posting code. Thank you.