Cant think through this textbox delimma

Hlatigo

Well-known Member
Joined
Jun 3, 2002
Messages
677
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

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
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
 
Upvote 0
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
 
Upvote 0
Sorry I don't understand.

What values are being entered on the form?

How did my code not work?

How did you try it?
 
Upvote 0
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
 
Upvote 0
So are you converting values like say 50 to 50%?
 
Upvote 0
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?
 
Upvote 0
Don't let the user enter percentages?:)
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,716
Members
448,985
Latest member
chocbudda

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?

Disable AdBlock

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
Back
Top