# Cant think through this textbox delimma

#### Hlatigo

##### Well-known Member
I have three text boxes and they are the probability of a occurance happening.

The problem I have is that, I cant have them add up to more than 1. If one textbox has .49, the other two cannot equal above .51. All I want is for a msgbox to pop up once the caluculate button is pressed that states all three probability boxes must equal to 1.

these are the names if it helps,
txtprob1.
txtprob3.
txtprob4.

cmdcalculate2

thanks for your help.
Latigo

### Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.

#### Norie

##### Well-known Member
Are they on a userform?

Code:
``````Private Sub cmdcalculate2_Click()
If Val(txtprob1)+Val(txtprob3)+Val(txtprob4)> 1 Then
Msgbox "All three probability boxes must equal to 1."
Exit Sub
Else
' continue with rest of code
End If
End Sub``````

#### Hlatigo

##### Well-known Member
Yes they are all on a userform. I will try your code. thanks so much Norie

#### Hlatigo

##### Well-known Member
Hello Norie or anyone who may want to add their thought!

the code isn't working to great right now because I have the following which validates and formats in case the user does not input in the form of a decimal or percentage. so when it add up the value in your code, it isn't reading right. Any thoughts? TY!!

Code:
``````Private Sub txtprob3_AfterUpdate()

On Error Resume Next

If txtPROB3.Value <> IsNumeric(txtPROB3.Value) Then
txtPROB3.Value = ""
MsgBox ("Need to enter proper numeric Value")
End If

If txtPROB3.Value > 1 Then
txtPROB3.Value = txtPROB3.Value / 100
FormatPercent (txtPROB3.Value)
End If
End sub``````

#### Norie

##### Well-known Member

Sorry I don't understand.

What values are being entered on the form?

How did my code not work?

How did you try it?

#### Hlatigo

##### Well-known Member
I dont think it is your code but how I formatted the box to be a percent. when i hit calculate it will allow it to continue even if the three boxes do not equal to one. I am not to sure where to fix it. Should I convert it to just decimals and not percent? if so...i havent found a way to convert to decimals only.

Latigo

#### Norie

##### Well-known Member

So are you converting values like say 50 to 50%?

#### Hlatigo

##### Well-known Member
Yes I am converting them incase that leave it as a whole number, if it is place in as a decimal than it is left alone. I tired to convert your code into assuring that is is a percent but that hasnt worked. any ideas?

#### Norie

##### Well-known Member
Don't let the user enter percentages?

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

### Forum statistics

1,163,988
Messages
5,834,727
Members
430,314
Latest member
Kym_beginner_in_VBA

### We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

### Which adblocker are you using?

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

### Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

### Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

### Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back