2016-08-25 21 views
1
Private Sub ROLparameter_Click() 
Line1: RolLow = InputBox("Please enter the lower bound percentage for ROL calculation between 0 and 100 (initially " & RolLow * 100 & "%):") 

If Not 0 <= RolLow <= 100 Then GoTo Line1 
End If 

End Sub 

我有用戶表單按鈕,當我按下它時會進入這個子分區。問題是它給出了錯誤「如果沒有,如果結束」。當我刪除結束時,它奇怪地工作。VBA用戶表單不能識別功能?

如;

它確實將用戶輸入80時的RolLow值識別爲「80」。如果不指示它結束sub,如果我只使用「if」,那麼它將直接指向第1行。沒有檢查價值。

此代碼在模塊中正常工作。

可能是什麼問題?

(變量潛艇之前定義的公共)

(我試過module.variable東西也)

+0

嘗試的代碼在我的回答如下 –

回答

0

這是您要運行代碼: 如果用戶輸入小於0的值或大於100,然後回到的InputBox

Private Sub ROLparameter_Click() 

Line1: Rollow = CLng(InputBox("Please enter the lower bound percentage for ROL calculation between 0 and 100 (initially " & Rollow * 100 & "%):")) 

If Not ((0 <= Rollow) And (Rollow <= 100)) Then 
    GoTo Line1 
End If 

End Sub 
+0

非常感謝!什麼是CLng?我想學習:) – hakandeep

+0

'CLng'將輸入(作爲字符串接收)轉換爲長整型,如果需要更小的值,也可以使用'CInt' –

+0

再次感謝! – hakandeep