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

I have user form button, when I press it will enter this sub. The problem is it gives error "end if without if". When I remove end if, it works strangely.

Such as;

it does recognize the RolLow value when user enter 80, as "80". If not directs it to end sub, if i use only "if" then it will direct to line 1 all the time. No checking of the value.

This code working normally in a module.

What can be the problem?

(Variables are defined public before the subs)

(i tried module.variable thing also)

1
  • try the code in my answer below Commented Aug 25, 2016 at 8:03

1 Answer 1

0

This is the code you are trying to run: if the user inputs a value smaller than 0 or larger than 100, then go back to 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
Sign up to request clarification or add additional context in comments.

2 Comments

CLng converts the input (received as String) into Long, you can use alsoCInt if you want for smaller values
Thanks a lot again!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.