Results 1 to 4 of 4

Thread: textbox calculation

  1. #1

    textbox calculation

    morning all

    i have a form which has a few text boxes on it and i have wrote the code to find the average of the 4 boxes (added them together then divided by 4, used .controls, val and .text

    now i would like to find the varition between the 4 for example if the 4 values are

    1, 1.005, 1.003 and 1.002

    the variation is 1.005-1.000=0.005

    basically the max-min but vba doesnt appear to recognise max and min unless i am doing something wrong?

    also would like to set the format of the boxes used

    textbox1= format(textbox1,"0.0000") which works fine if i use a BeforeUpdate event but this relies on moving to another box which is ok until you reach the last box?

    i would appreciate if anyone could point me in the right direction

    thanks in advance

  2. #2
    Moderator VBAX Guru Simon Lloyd's Avatar
    Sep 2005
    Take a look at, it will have a lot of information to set you on the right track!
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  3. #3
    you can write code that runs every time a change occurs in the textbox but imagine if you wanted to enter 23 you would enter 2 then the coe would kick in and format the cell as 2.0000 then where is your cursor ? for when you type the 3 ?

    A better way is to load the boxes with "0.0000" when you start and then format them as you leave (as you are doing). It gives the user a clue as to what is expected, You can also have the OK (or whatever) run the format's for you anyway, so they are all updated before any subsequent use.
    2+2=9 ... (My Arithmetic Is Mental)

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master xld's Avatar
    Apr 2005
    Use Application.MAX(Val(TextBox1.Text), Val(TextBox2.Text),...

    and Application.Min
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

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