1
我正在創建一個概率宏,用戶在卡片遊戲中輸入玩家人數。如果輸入字符串(例如,Joe
),非整數(例如,15.67
)或小於0的整數(例如-25
),InputBox應該循環。但是,大於0的整數應該終止循環。 (我必須迫使Excel停止輸入框,無論用戶輸入如何。)Do Until Loop InputBox無限循環
我希望InputBox在輸入大於0的整數後關閉/退出Sub。我在這裏做錯了什麼?
Sub GenerateCards()
Players = InputBox("How many players? Please enter an integer.")
Do Until TypeName(Players) = "Integer" And Players > 0 ' why does this loop even if both conditions are met (ex, Players=5?)
Players = InputBox("How many players? Please enter an integer.")
Loop
End Sub
謝謝,我會嘗試一些字符串,小數和各種整數。 –
好吧,我試過了,它可以在所有運行時實例中完美地工作。謝謝! –