1
Private Sub CommandButton1_Click()
  TextBox2.Value = 10
  TextBox3.Value = 5
  TextBox2.Value = (CInt(TextBox2))
  TextBox3.Value = (CInt(TextBox3))

  If TextBox2.Value > TextBox3.Value Then
    ActiveSheet.Select
    UserForm5.Show
  End If
End Sub

The control is not going in the IF loop, and "USerForm5 is not getting displayed.

Can anyone pls help.

Reagrds

4
  • What is TextBox2.Value = (CInt(TextBox2)) is used for? Commented Mar 13, 2011 at 7:43
  • 1
    FYI, IF is not a loop, it's a control structure. Commented Mar 13, 2011 at 7:58
  • Most likely that TextBox.Value property cannot hold an integer and converts it back to string. Nice little gotcha. Commented Mar 13, 2011 at 8:02
  • 1
    It is common in StackOverflow to Accept answers that work by selecting the large tick. An up vote is always good, too. Answers that help, but do not solve the problem can also be up-voted. You will find notes in the FAQ in the top bar. Commented Mar 13, 2011 at 11:14

1 Answer 1

4

The comparison is being done as strings. Wrap the CInt() calls around the values in the IF statement and you'll be good.

TextBox2.Value = 10
TextBox3.Value = 5
If CInt(TextBox2.Value) > CInt(TextBox3.Value) Then
Sign up to request clarification or add additional context in comments.

Comments

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.