Consulting

Results 1 to 6 of 6

Thread: Add values when checkbox is checked.

  1. #1
    VBAX Regular
    Joined
    Oct 2007
    Posts
    97
    Location

    Add values when checkbox is checked.

    Hi guys,
    I have 10 textbox filled with values.
    Next to each textbox I have a checkbox.
    What I want to accomplish is to add all the textbox(s) for which the checkbox is checked.

    I was able to do it for two check box, Now that i am going for more, I know that i need to create a loop. I know the logic of it, but I am having hard time to see where to put the variable.

    Can anyone help me with that?

  2. #2
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    On a sheet or on a userform?
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  3. #3
    VBAX Regular
    Joined
    Oct 2007
    Posts
    97
    Location
    Userform.

  4. #4
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Can you post your workbook with the userform so we don't have to re-create your scenario?
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  5. #5
    VBAX Regular
    Joined
    Oct 2007
    Posts
    97
    Location
    Here is what I have so far.


    [vba]Private Sub CommandButton1_Click()

    Dim i As Integer
    Dim s As double
    Dim a As double
    s = 0
    a = 0
    For i = 1 To 10
    If Me.Controls("Checkbox" & i).Value = True Then
    a = Me.Controls("textbox" & i).Text
    s = Val(s) + Val(a)
    End If
    Next i
    Textbox11.text = val(s)

    End Sub[/vba]

  6. #6
    VBAX Regular
    Joined
    Oct 2007
    Posts
    97
    Location
    I figured it out.
    Thank you though Lucas for your initiative in helping me.

Posting Permissions

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