Textbox fomatting value based on another textbox

J

job

I have two text boxes on a form. One is a value that can be changed by the
user. The second is the value 1 - textbox1. I need everthing to be in %.
For example, in textbox1 the user could type 75 and it would automatically
be recognized as 75% and textbox2's value would calculate to be 25%.
Everytime I try textbox1's value is = to say 7500%. Any help is
appreciated.

Cheers,

Job
 
D

Dave Peterson

Maybe something like:

Option Explicit
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim TB1Val As Double
With Me.TextBox1
If IsNumeric(.Value) Then
TB1Val = CDbl(.Value)
.Value = Format(.Value / 100, "0.00%")
Me.TextBox2.Value = Format((1 - TB1Val / 100), "0.00%")
End If
End With
End Sub
 
J

Job

Perfect! Thanks Dave
Dave Peterson said:
Maybe something like:

Option Explicit
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim TB1Val As Double
With Me.TextBox1
If IsNumeric(.Value) Then
TB1Val = CDbl(.Value)
.Value = Format(.Value / 100, "0.00%")
Me.TextBox2.Value = Format((1 - TB1Val / 100), "0.00%")
End If
End With
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top