+ Reply to Thread
Results 1 to 11 of 11

Sum multiple TextBox giving live total

  1. #1
    Registered User
    Join Date
    11-25-2012
    Location
    Swansea, Wales
    MS-Off Ver
    Excel 2003
    Posts
    55

    Sum multiple TextBox giving live total

    My TextBox's are called Number1, Number2 and on up to Number20.

    I need to sum all these boxes in TextBox1.

    Not all of the Number(!) boxes are used every time.

    I have tried lots of different things but all I get is 0 in TextBox1.


    Just some of the things i have tried....

    Please Login or Register  to view this content.
    Last edited by Wales MB; 11-25-2012 at 08:08 PM. Reason: Solved

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Sum multiple TextBox giving live total

    The only way I can see you ending up with a pair of brackets in the textbox would be if one of the textboxes had () in it or one textbox has ( and another ).

    If you did have 20 textboxes named Number1, Number2 etc you could sum them like this.
    Please Login or Register  to view this content.
    PS TypeName will return the name of the type of control here, for example TextBox.
    If posting code please use code tags, see here.

  3. #3
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Sum multiple TextBox giving live total

    Try

    Please Login or Register  to view this content.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  4. #4
    Registered User
    Join Date
    11-25-2012
    Location
    Swansea, Wales
    MS-Off Ver
    Excel 2003
    Posts
    55

    Re: Sum multiple TextBox giving live total

    Please Login or Register  to view this content.
    Just 0 in TextBox1 - (looking at what i thought was () i now see its 0)

  5. #5
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Sum multiple TextBox giving live total

    This code will only be run when the worksheet is activated.

    If you want a 'live' total you need to move it so it runs every time a textbox changes.

  6. #6
    Registered User
    Join Date
    11-25-2012
    Location
    Swansea, Wales
    MS-Off Ver
    Excel 2003
    Posts
    55

    Re: Sum multiple TextBox giving live total

    Quote Originally Posted by Norie View Post
    This code will only be run when the worksheet is activated.

    If you want a 'live' total you need to move it so it runs every time a textbox changes.

    Please Login or Register  to view this content.
    This works but is there another way without a Private Sub for each Number (TextBox)?

  7. #7
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Sum multiple TextBox giving live total

    Move the loop to a separate sub and call it from each change event.
    Please Login or Register  to view this content.
    Or you could use a class, see the attached workbook for a simple example.
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    11-25-2012
    Location
    Swansea, Wales
    MS-Off Ver
    Excel 2003
    Posts
    55

    Re: Sum multiple TextBox giving live total

    Can you please have a look at my file I followed the example you sent but still can't get mine to work.....

    Yours works well but when i copy the code to mine no sums.
    Attached Files Attached Files

  9. #9
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Sum multiple TextBox giving live total

    It should be UserForm_Initialize.

    Like I said earlier TypeName will return the type of the control, eg TextBox, CommandButton.

    Try checking the name of the control.
    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    11-25-2012
    Location
    Swansea, Wales
    MS-Off Ver
    Excel 2003
    Posts
    55

    Re: Sum multiple TextBox giving live total

    Thank you - finally got it to work..... I am knackered i have been on this all day....

    Now if i want to also get TextBox2 to add all TextBoxes called Amount1, all the way up to Amount20.......

    What would i change??

  11. #11
    Registered User
    Join Date
    11-25-2012
    Location
    Swansea, Wales
    MS-Off Ver
    Excel 2003
    Posts
    55

    Re: Sum multiple TextBox giving live total

    Please Login or Register  to view this content.
    worked........

    I thank you for all your help......

+ 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