Hi Everyone,
I have TextBox1 in a userform. When somebody opens up the userform the textbox is prepopulated with a number already in it (.31), however I did leave the option for the user to change this number if needed. The reason why there's a decimal because when the number is submitted on the userform it populates as a percentage in a excel worksheet. I am trying to make it so that a user can not input a number greater than .100 (100%) in the textbox.
I have the code below but I think the decimals messes up my code for whatever reason? Also when I go to change the .31 to a random number, as soon as I type in (.1) the error message pops up, even if the value is supposed to be (.15) which is in the correct range. However the message should only pop up if the user inputs a number like (.101). Is there a way to fix this? Thank you for your help in advance!
Private Sub TextBox1_Change()
If TextBox1.Value > -0.01 And TextBox1.Value > 0.101 Then
TextBox1.Value = TextBox1.Value
Else
MsgBox "Number Range Must Be Between 0 - 100%, Can Not Exceed 100%."
End If
End Sub
I have TextBox1 in a userform. When somebody opens up the userform the textbox is prepopulated with a number already in it (.31), however I did leave the option for the user to change this number if needed. The reason why there's a decimal because when the number is submitted on the userform it populates as a percentage in a excel worksheet. I am trying to make it so that a user can not input a number greater than .100 (100%) in the textbox.
I have the code below but I think the decimals messes up my code for whatever reason? Also when I go to change the .31 to a random number, as soon as I type in (.1) the error message pops up, even if the value is supposed to be (.15) which is in the correct range. However the message should only pop up if the user inputs a number like (.101). Is there a way to fix this? Thank you for your help in advance!
Private Sub TextBox1_Change()
If TextBox1.Value > -0.01 And TextBox1.Value > 0.101 Then
TextBox1.Value = TextBox1.Value
Else
MsgBox "Number Range Must Be Between 0 - 100%, Can Not Exceed 100%."
End If
End Sub
Last edited: