+ Reply to Thread
Results 1 to 4 of 4

Using TextBoxes to Subtract a constant value from another TextBox

  1. #1
    Registered User
    Join Date
    12-03-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    50

    Using TextBoxes to Subtract a constant value from another TextBox

    Hello,

    I'm looking for ideas on how I might go about coding a subtraction procedure. I have four textboxes. Textbox1 has a value of 100. Textboxes2-4 are zero. If I enter a value in either textboxes2-4 that value is subtracted from Textbox1. There is a limit. Textbox1 must never be less than 0. The user can either receive a MessageBox or further entry is prohibited. I would prefer a MessageBox alert.

    I have attached a Userform1 as reference. Book1.xlsm

    Thank you in advance.

    Gal.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Using TextBoxes to Subtract a constant value from another TextBox

    Hello Gal403,

    The code shown for the UserForm has been tested. Delete any code in the UserForm and paste this code in it's place.

    UserForm Code
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    12-03-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    50

    Re: Using TextBoxes to Subtract a constant value from another TextBox

    Thank you very much Leith! I was able to come up with my own an hour ago but found my coding awkward. I really like yours and it's doing exactly what I need so I'm going to use it although its over head. Question: What is happening here when code this "Function ZeroValueCheck(ByRef Ctrl As Control) As Boolean" ?

    Many Thanks. Sincerely,
    Gal

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Using TextBoxes to Subtract a constant value from another TextBox

    Hello gal,

    The ZeroValueCheck passes a reference to the calling object using the argument variable Ctrl. In your code, the function is called by TextBox2, TextBox3, or TextBox4. When the function is called it will sum the values of TextBox2, TextBox3, and TextBox4. This sum is then subtracted from the initial value of 100.

    The difference is checked if it is below zero. If true then user is notified the result is less than zero with a message box. The text box that Ctrl refers to is set to zero, the cursor is placed at the start, and the zero is highlighted. ZeroValueCheck returns true.

    The TextBox_Exit event has an argument Cancel. Setting this to true will prevent the cursor from moving to the next control on the UserForm and allowing the user to re-enter the value.

+ 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. [SOLVED] URGENCY: Textbox does the union of the other textboxes
    By carapins in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-17-2013, 07:05 AM
  2. [SOLVED] Several Textboxes values into one textbox
    By sagar007 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 10-17-2012, 08:11 AM
  3. If TextBox has value set visible other TextBoxes, if not set false
    By john55 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-02-2011, 02:53 PM
  4. How to update textbox from other textboxes
    By chris0374 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-12-2010, 04:20 PM
  5. Display constant time in textbox
    By mikewild2000 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-23-2005, 06:57 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