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
 

Some videos you may like

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,218
Office Version
  1. 365
Platform
  1. Windows
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
Joined
Jun 3, 2002
Messages
677
Yes they are all on a userform. I will try your code. thanks so much Norie
 

Hlatigo

Well-known Member
Joined
Jun 3, 2002
Messages
677
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
Joined
Apr 28, 2004
Messages
76,218
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

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
Joined
Jun 3, 2002
Messages
677
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
Joined
Apr 28, 2004
Messages
76,218
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

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

Hlatigo

Well-known Member
Joined
Jun 3, 2002
Messages
677
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
Joined
Apr 28, 2004
Messages
76,218
Office Version
  1. 365
Platform
  1. Windows
Don't let the user enter percentages?:)
 

Watch MrExcel Video

Forum statistics

Threads
1,122,747
Messages
5,597,905
Members
414,189
Latest member
Duque_

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
Top