+ Reply to Thread
Results 1 to 9 of 9

Userform Calculation

  1. #1
    Registered User
    Join Date
    05-29-2012
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    63

    Userform Calculation

    I have a basic userform where I want to calculate "hours worked" figures against 10 employees.

    For each employee a calculation works out the total cost based upon an "hourly" rate in an adjacent text box. i.e. text box1 = hours worked, text box 2 = hourly rate and textbox 3 = calculation. This work fines with each employee.

    The problem comes with the sum box at the end, I basically want to add textbox 3,6,9,12, and 15 (the costs for each employee) into textboxWAGESCOST.

    The calculation in the text box only works when i enter something into textboxWAGESCOST, but I want the total to count up/update as I go along?!

    My code is below....can anyone help please?

    Please Login or Register  to view this content.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645
    Use the change event of the other textboxes to do the sum and place the result.
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    05-29-2012
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    63

    Re: Userform Calculation

    Thanks for the reply, but i'm not really sure what you mean?

  4. #4
    Registered User
    Join Date
    11-26-2012
    Location
    Kitchener, Ontario, Canada
    MS-Off Ver
    Excel 2010
    Posts
    82

    Re: Userform Calculation

    One way is to ceate a sub routine like this
    Please Login or Register  to view this content.
    then call up this routine under each boxes(3,6, 9, 12) e.i like this
    Please Login or Register  to view this content.
    of course you are going to delete the code for sum box TextBoxWAGESCOST
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    05-29-2012
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    63

    Re: Userform Calculation

    Thanks for the response, I've tried changing the code but i'm getting a mis-match error.

    I've attached an example workbook as I might be missing something huge?

    Thanks so much for your help
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    11-26-2012
    Location
    Kitchener, Ontario, Canada
    MS-Off Ver
    Excel 2010
    Posts
    82

    Re: Userform Calculation

    Attachment 197710You need add Val(string) function as follows
    Please Login or Register  to view this content.
    same for each for boxes 3, 6, 9, 12 i.e
    Please Login or Register  to view this content.
    Notice I added Trim(string) function as well to trim any leading or trailing spaces.

    I fixed your attached file and re-attached it again
    Attached Files Attached Files
    Last edited by aelgadi; 12-03-2012 at 09:43 AM. Reason: Re-attach file
    aelgadi

    > Click Star if I helped. Thanks

  7. #7
    Registered User
    Join Date
    05-29-2012
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    63

    Re: Userform Calculation

    Thank you so much!

  8. #8
    Valued Forum Contributor
    Join Date
    11-15-2008
    Location
    ph
    MS-Off Ver
    2007/2010/2016
    Posts
    479

    Re: Userform Calculation

    Hi -

    Type something on the left textbox then back space, the values in right textbox will remains, same thing with the total textbox.
    This is due to the exit sub.
    Just for fun, try this approach

    Regards,
    Event
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    11-26-2012
    Location
    Kitchener, Ontario, Canada
    MS-Off Ver
    Excel 2010
    Posts
    82

    Re: Userform Calculation

    I tried it with left textboxes working fine. the total textbox really should be locked.

+ 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