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

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.

Norie

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

Watch MrExcel Video

Forum statistics

Threads
1,118,811
Messages
5,574,454
Members
412,595
Latest member
slim313
Top