Consulting

Results 1 to 3 of 3

Thread: Count textbox values greater than 0

  1. #1
    VBAX Regular
    Joined
    Dec 2013
    Posts
    15
    Location

    Count textbox values greater than 0

    Hi,

    I wonder to count textbox values greater than 0 and I made this code but it's not working.

    Could someone help me please?

    Thanks

    Dim i As Integer
    Dim divisor As Integer
    
        divisor = 0
        
        For i = 1 To 11
            If ("TextBox" & i).Value > 0 Then
                divisor = dividor + 1
            End If
        Next i
    
    
    Dim soma As Long
        
        soma = TextBox1.Value + TextBox2.Value + TextBox3.Value + TextBox4.Value + TextBox5.Value + TextBox6.Value + TextBox7.Value + TextBox8.Value + TextBox9.Value + TextBox10.Value + TextBox11.Value
        
        Label203.Caption = soma \ divisor

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Dim i As Integer 
    Dim divisor As Integer 
     
    divisor = 0 
     
    For i = 1 To 11 
        If  Me.Controls("TextBox" & i).Value > 0 Then 
            divisor = dividor + 1 
        End If 
    Next i 
     
     
    Dim soma As Long 
     
    soma = TextBox1.Value + TextBox2.Value + TextBox3.Value + TextBox4.Value + TextBox5.Value + TextBox6.Value + TextBox7.Value + TextBox8.Value + TextBox9.Value + TextBox10.Value + TextBox11.Value 
     
    Label203.Caption = soma \ divisor
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Regular
    Joined
    Dec 2013
    Posts
    15
    Location
    It works!

    Thanks

Posting Permissions

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