View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
PaulW PaulW is offline
external usenet poster
 
Posts: 130
Default Textbox1.Value Question

Hi there,

I am working on a UserForm with three Textboxes (Texbox1, Textbox2 & Textbox3)
Each of the Textboxes are to store a number and display as a %.

What I am struggling to complete is for each of the three boxes when
combined do not total over 100% or over 100% invidiually.

Please see my code below so far:

Private Sub TextBox1_AfterUpdate()

a = TextBox1.Value
If Right(a, 1) = "%" Then a = Left(a, 2)
b = TextBox2.Value
If Right(b, 1) = "%" Then b = Left(b, 2)
c = TextBox3.Value
If Right(c, 1) = "%" Then c = Left(c, 2)

d = a + b + c
MsgBox (d)

If TextBox1.Value = "" Then Exit Sub
If Right(TextBox1.Value, 1) < "%" Then
If TextBox1.Value 100 Then
MsgBox ("Error")
TextBox1.Value = ""
Else: TextBox1.Value = TextBox1.Value & "%"
End If
End If
End Sub
Private Sub TextBox2_AfterUpdate()
a = TextBox1.Value
If Right(a, 1) = "%" Then a = Left(a, 2)
b = TextBox2.Value
If Right(b, 1) = "%" Then b = Left(b, 2)
c = TextBox3.Value
If Right(c, 1) = "%" Then c = Left(c, 2)

d = a + b + c
MsgBox (d)

If TextBox2.Value = "" Then Exit Sub
If Right(TextBox2.Value, 1) < "%" Then
If TextBox2.Value 100 Then
MsgBox ("Error")
TextBox2.Value = ""
Else: TextBox2.Value = TextBox2.Value & "%"
End If
End If
End Sub
Private Sub TextBox3_AfterUpdate()
a = TextBox1.Value
If Right(a, 1) = "%" Then a = Left(a, 2)
b = TextBox2.Value
If Right(b, 1) = "%" Then b = Left(b, 2)
c = TextBox3.Value
If Right(c, 1) = "%" Then c = Left(c, 2)

d = a + b + c
MsgBox (d)

If TextBox3.Value = "" Then Exit Sub
If Right(TextBox3.Value, 1) < "%" Then
If TextBox3.Value 100 Then
MsgBox ("Error")
TextBox3.Value = ""
Else: TextBox3.Value = TextBox3.Value & "%"
End If
End If
End Sub


Many thanks
Dan