+ Reply to Thread
Results 1 to 2 of 2

AVERAGE VALUES IN TEXTBOXES!!!!!

  1. #1
    michael sofianos
    Guest

    AVERAGE VALUES IN TEXTBOXES!!!!!

    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



  2. #2
    Dave Peterson
    Guest

    Re: AVERAGE VALUES IN TEXTBOXES!!!!!

    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

    michael sofianos wrote:
    >
    > 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


    --

    Dave Peterson

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1