Consulting

Results 1 to 4 of 4

Thread: Summing textboxes

  1. #1
    VBAX Regular
    Joined
    Jun 2013
    Posts
    40
    Location

    Summing textboxes

    I have 31 textboxes on a userform. Each box represents a budget figure for that day. The textboxes are "t1" through "t31" and the sum is to appear in "tt".

    This is what is NOT working for me.

    Private Sub t31_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    Dim x As Long, lCount As Long
    For x = 1 To 31
    If Me.Controls("t" & x) = "*" Then lCount = lCount + Val(Me.Controls("t" & x).Text)
    Next x
    tt = lCount
    End Sub

  2. #2
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    below worked for me:

        For x = 1 To 31
            lCount = lCount + Val(Controls("t" & x))
        Next x
        tt = lCount


    i think you want to test if any textbox is empty.

    Val function returns 0 if the string does not contain a numeric value.

    Sub test()
        MsgBox Val("6th ave")
        MsgBox Val(6)
        MsgBox Val("")
        MsgBox Val(" ")
    End Sub
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  3. #3
    VBAX Regular
    Joined
    Jun 2013
    Posts
    40
    Location
    Most excellent!

    I love this:"... Make my enemy brave and strong, so that if defeated, I will not be ashamed..." Big Lodge Pole, Blackfeet

    Blackfoot is in my heritage.

  4. #4
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    you are welcome.



    "Give wisdom and understanding to my leaders.
    Protect my warriors and bring them back safe.
    Give to the young, love and contentment.
    Give health and long life to my old people so that they may remain with us for a long time.
    Make my enemy brave and strong, so that if defeated, I will not be ashamed.
    And give me wisdom so that I may have kindness for all.
    And let me live each day, so when day is done, my prayer will not have been in vain."

    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

Posting Permissions

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