+ Reply to Thread
Results 1 to 12 of 12

Button to calculate multiple math operations in a userform, at once

  1. #1
    Forum Contributor
    Join Date
    07-15-2016
    Location
    Maputo, Mozambique
    MS-Off Ver
    2007
    Posts
    108

    Question Button to calculate multiple math operations in a userform, at once

    Hi good people,
    I have a userform that gets some data (numbers) from a database sheet when initialize. Good. It works.
    I put there a command button to launch the calculation inside the userform.
    It works too, BUT I have to click the button several time to complete all the calculations.

    Why? And how can avoid it? I would like to click once on the calculate button and have all the calculations done. In one click.

    Here the code of the buttons. Remember, it works but require several click to complete:

    Please Login or Register  to view this content.
    It is not really important where the data came from or is going... I just, need to learn how to calculate the operations in red with one click!

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,660

    Re: Button to calculate multiple math operations in a userform, at once

    I don't know the nature of your data, but it looks like you are calculating values with decimals. The variables you declare are type Long which are large integers. Perhaps if you declared them as Double e.g.;

    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Forum Contributor
    Join Date
    07-15-2016
    Location
    Maputo, Mozambique
    MS-Off Ver
    2007
    Posts
    108

    Re: Button to calculate multiple math operations in a userform, at once

    Hi AlphaFrog, thank for answer me.

    I changed the "long" with the "double". Thanks for the tip. (but i swear it was working anyway!)

    Unfortunately the button must be clicked 3 times anyway to calculate all.....

    It is like the code calculates the first 6 (red) lines at once, than the 7th, than the last.
    I think it is due to the fact that the first 6 lines calculate values that immediately appear in the form (i can see some of the calculations done at first click).
    Than it is needed a second click for line 7, that create the value "adescfaltas" and put in the form. (i can see it too).

    Then, the 3d click is for the last line. So it is like i will have to run the macro 3 times... I wonder how....

    Or, maybe, do all the calculation before writing in the form... with some hidden textbox for example... but i do not like the idea...

  4. #4
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,637

    Re: Button to calculate multiple math operations in a userform, at once

    This shouldn't normally b any problem. Can you post example file with your userform in it ?
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  5. #5
    Forum Contributor
    Join Date
    07-15-2016
    Location
    Maputo, Mozambique
    MS-Off Ver
    2007
    Posts
    108

    Re: Button to calculate multiple math operations in a userform, at once

    Hi bakerman2, i will do it later after work...

  6. #6
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Button to calculate multiple math operations in a userform, at once

    At a guess your issue is the order of your code
    Please Login or Register  to view this content.
    the highlighted lines show that you assign the value of the TAXAHORA control to the ataxahora variable, then your code changes the value of the control but never updates the variable before using the variable in the third highlighted line. I presume that was not what you needed.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  7. #7
    Forum Contributor
    Join Date
    07-15-2016
    Location
    Maputo, Mozambique
    MS-Off Ver
    2007
    Posts
    108

    Re: Button to calculate multiple math operations in a userform, at once

    Hi, got an unexpected shift change at work... good for the coding!

    I made up an example file.
    The database contains lots of columns but i only retrieve data from some of them, the ones needed for calculation.
    Open the file. Click on the name Alex Piotto (the only name i left there for testing purposes. Data is fake).

    The form will pop up with some values already in place, others will be zeros.

    As it is, click CALCULAR, one, two, three times, until the TOTAL do not changes anymore.

    You can change the values of the green labeled textboxes in order to test if the math is OK.

    What do you think? It is an order problem, as xlnitwit suggests?
    Attached Files Attached Files
    Last edited by Alex Piotto; 03-26-2018 at 03:40 AM.

  8. #8
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,637

    Re: Button to calculate multiple math operations in a userform, at once

    Think I figured it out.
    Please Login or Register  to view this content.

  9. #9
    Forum Contributor
    Join Date
    07-15-2016
    Location
    Maputo, Mozambique
    MS-Off Ver
    2007
    Posts
    108

    Re: Button to calculate multiple math operations in a userform, at once

    Until now I managed to BRUTALLY call the function 3 times... now it calculates all in one click. But surely exists a better way!

    Please Login or Register  to view this content.

  10. #10
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,637

    Re: Button to calculate multiple math operations in a userform, at once

    Did you try my code from Post#8 ?

  11. #11
    Forum Contributor
    Join Date
    07-15-2016
    Location
    Maputo, Mozambique
    MS-Off Ver
    2007
    Posts
    108

    Re: Button to calculate multiple math operations in a userform, at once

    Sorry i posted mine but yours was not there yet. I will try right now!

    Tested and it is working. Thank you all for the help.
    Last edited by Alex Piotto; 03-26-2018 at 05:43 AM.

  12. #12
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,637

    Re: Button to calculate multiple math operations in a userform, at once

    Glad to help and thanks for rep+.

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.

+ 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. Excel Case/else structure math operations.
    By bigdog332 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-03-2013, 10:36 AM
  2. [SOLVED] Math operations with data from LabVIEW in .TXT
    By bakito in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 05-06-2013, 07:11 AM
  3. Excel Case/else structure math operations.
    By LadyB in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-14-2013, 01:58 AM
  4. math operations
    By stonecoldmike in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-17-2012, 05:53 PM
  5. Applying math operations on time values
    By emanon132501 in forum Excel General
    Replies: 6
    Last Post: 02-09-2011, 03:35 PM
  6. Replies: 9
    Last Post: 02-01-2011, 01:41 AM
  7. Excel 2007 : math operations with text
    By djv0001 in forum Excel General
    Replies: 2
    Last Post: 02-05-2009, 05:14 PM

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