AVERAGE VALUES IN TEXTBOXES!!!!!

M

michael sofianos

Hello to all friends,

I have 7 textboxes in the same line into userform. I want to see , after to
put values of each of one these textboxes to get the average values (of
preview 6 textoxes) in the 7th textbox . ( but when a change the value in
one of the 6 texboxes the average of 7th must be change).

example,

a | b | c | d | f | g | k

k = (a+b+c+d+f+g)/6

Thanks
 
D

Dave Peterson

How about something like:

Option Explicit
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Call DoAvgTB
End Sub
Private Sub TextBox2_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Call DoAvgTB
End Sub
Private Sub TextBox3_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Call DoAvgTB
End Sub
Private Sub TextBox4_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Call DoAvgTB
End Sub
Private Sub TextBox5_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Call DoAvgTB
End Sub
Private Sub TextBox6_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Call DoAvgTB
End Sub
Sub DoAvgTB()
Dim iCtr As Long
Dim myTotal As Double
Dim myCount As Long
Dim maxTB As Long

maxTB = 6

myTotal = 0
myCount = 0
For iCtr = 1 To maxTB
With Me.Controls("textbox" & iCtr)
If IsNumeric(.Value) Then
myCount = myCount + 1
myTotal = myTotal + CDbl(.Value)
End If
End With
Next iCtr

If myCount > 0 Then
Me.Controls("TextBox" & maxTB + 1).Value _
= Format(myTotal / myCount, "#,##0.000")
Else
Me.Controls("Textbox" & maxTB + 1).Value = "Error"
End If

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