+ Reply to Thread
Results 1 to 8 of 8

result auto reflect when input value changes

  1. #1
    Registered User
    Join Date
    02-28-2014
    Location
    Dubai
    MS-Off Ver
    Excel 2013
    Posts
    19

    Post result auto reflect when input value changes

    Hello,

    I need your help to sort this issue.

    I have userform with three numeric text items, two take input from the user and third used to display the result.
    As you can see the following snippet which will show result by pressing CommandButton1 after taking inputs from the users. Now my intentions to remove the button and to display the result automatically when user enter the values in gross.text and eprem.text. Kindly advise!
    Please Login or Register  to view this content.

  2. #2
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,863

    Re: result auto reflect when input value changes

    have a closer look on gross_Change and eprem_Change procedures (if you dont have them yet - create them first. Easiest way rightclick on textbox in while in VBA editor and select show code),
    Best Regards,

    Kaper

  3. #3
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,905

    Re: result auto reflect when input value changes

    Quote Originally Posted by crimzon View Post
    display the result automatically when user enter the values in gross.text and eprem.text
    How will you know when the user is done entering the values?

    The Change event is triggered by every change, including typing one more character. How will you know when the user is done typing?
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  4. #4
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,863

    Re: result auto reflect when input value changes

    I do not think it matters, moreover in number of cases it is a desired behaviour.
    Once typing is finished the final results appear, and in a meanwhile - partial.

    Of course, if it matters and one wants only final result, not partial, one could use gross_AfterUpdate and eprem_AfterUpdate events handlers instead of X_Change ones.
    Then the updating would be done after gross and/or eprem loose focus.
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    02-28-2014
    Location
    Dubai
    MS-Off Ver
    Excel 2013
    Posts
    19

    Re: result auto reflect when input value changes

    Quote Originally Posted by Kaper View Post
    I do not think it matters, moreover in number of cases it is a desired behaviour.
    Once typing is finished the final results appear, and in a meanwhile - partial.

    Of course, if it matters and one wants only final result, not partial, one could use gross_AfterUpdate and eprem_AfterUpdate events handlers instead of X_Change ones.
    Then the updating would be done after gross and/or eprem loose focus.

    Thank you very much for your kind help.

    Sir, if i want to put this functionality for all input textbox, checkbox on the userform, it would be very useless practice to write for textitems.
    Is there any way to write a one sub for all changes occurred in textbox or checkbox?


    Kindly also tell how to handle divide by zero exception in your attached macro? you only used + and x operator but when i used / (Divide) it raised exception divide by zero. kindly advise on it also.
    Last edited by crimzon; 03-05-2014 at 01:07 AM.

  6. #6
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,863

    Re: result auto reflect when input value changes

    as for exception - you used sum in your example, so did I of course with division it would be wise to have something like:
    Please Login or Register  to view this content.

    for several controls simple way would be to move all computations and result displaying in one procedure which could be called from each event handler, like:
    Please Login or Register  to view this content.
    note that in gross field I used AfterUpdate event handler (so do_job is called after finished editing, while in eprem i left Change (do_job called after each change within)
    I added 4 more controls just to show that all computations are done in one procedure taking into account state all controls on the form.
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    02-28-2014
    Location
    Dubai
    MS-Off Ver
    Excel 2013
    Posts
    19

    Re: result auto reflect when input value changes

    thank you very much Sir for you precious time and help

  8. #8
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,905

    Re: result auto reflect when input value changes

    If your question has been answered please mark your thread as "Solved" so that members will know by looking at the thread title that your problem is solved.

    Go to the menu immediately above your first post to the thread and click on Thread Tools. From the dropdown menu select "Mark this thread as solved..."

    If a member helped you solve your problem, consider adding to their reputation by clicking on the star icon below their name.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Auto populating of formula with result based on input data and party name
    By paradise2sr in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-01-2013, 02:56 AM
  2. How do I auto change text colour in excel to reflect the value ent
    By Ashish Mathur in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-06-2005, 04:05 AM

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