+ Reply to Thread
Results 1 to 14 of 14
  1. #1
    Registered User
    Join Date
    05-07-2009
    Location
    Chesham,England
    MS-Off Ver
    Excel 2003 (11.5612.5606)
    Posts
    30

    Calculate Button

    Hello I am trying to create a Radio button in a cell that calculates the entire workbook rather than pressing F9.

    I am not friendly with macro's yet so would prefer not to use any but I must learn....

    Cheers

    Martyn

  2. #2
    Forum Moderator shg's Avatar
    Join Date
    06-21-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2007
    Posts
    25,131

    Re: Calculate Button

    Create an AutoShape or Forms button, and assign this macro:
    Code:
    Sub Calc()
        Calculate
    End Sub
    Microsoft MVP - Excel
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Guru JBeaucaire's Avatar
    Join Date
    03-21-2008
    Location
    Bakersfield, CA
    MS-Off Ver
    2010
    Posts
    18,225

    Re: Calculate Button

    I can't fathom how creating and coding a special button is better than just pressing F9. There is always the moment when we all "need to learn them", as you say, but I don't see how this qualifies.

    Anyway. Simplest:

    1) Turn on the Control Toolbox Toolbar
    2) Click on Command Button icon
    3) Draw your button on your sheet somewhere (it will appear with a name like CommandButton1)
    4) Right click on your new button and select Properties
    5) Find the Caption and change "CommandButton1" to "Calculate"
    6) Set your Font choice and BackColor choice
    7) Set TakeFocusOnClick to False (this will keep your activecell focus where it is, even when you click the button)
    8) Close the Properties window
    9) Right-click the button and select VIEW CODE, a VBA window will appear with header/footer for your command button already there, but no code in between, add the word Calculate in between.
    Code:
    Private Sub CommandButton1_Click()
        Calculate
    End Sub
    10) Press ALT-Q to close the VBEditor.
    11) Save your sheet.
    12) On the Control Toolbox toolbar, click on the EXIT DESIGN MODE button

    Your button is now active. Click your button to calculate the workbook.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    “None of us is as good as all of us” - Ray Kroc
    “Actually, I *am* a rocket scientist.” - JB (little ones count!)

  4. #4
    Registered User
    Join Date
    05-07-2009
    Location
    Chesham,England
    MS-Off Ver
    Excel 2003 (11.5612.5606)
    Posts
    30

    Re: Calculate Button

    Hi Thank you very much.

    As for the reasoning I am writing a program, and I have created a data entry sheet I wanted the button as not all the program users will know that F9 is calculate and on auto calculate all the result cell's have Divide by 0 errors.

  5. #5
    Forum Guru JBeaucaire's Avatar
    Join Date
    03-21-2008
    Location
    Bakersfield, CA
    MS-Off Ver
    2010
    Posts
    18,225

    Re: Calculate Button

    Quote Originally Posted by martynduerden View Post
    As for the reasoning I am writing a program, and I have created a data entry sheet I wanted the button as not all the program users will know that F9 is calculate
    1) A note on the sheet "Press F9 to calculate" pretty much educates new users.

    ...and on auto calculate all the result cell's have Divide by 0 errors.
    2) Any formula that divides by a cell that could be empty should be rewritten. If the formula =A1/B1 gives an error when B1 is empty, evaluate cell B1 first....like so:

    =IF(B1=0,"",A1/B1)

    That technique can be adapted to solve most equations that result in errors when data is missing. It's a habit worth getting into and is far more useful than turning off calculations and hope you/others remember to update by pressing F9 or a button.

    My two cents.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    “None of us is as good as all of us” - Ray Kroc
    “Actually, I *am* a rocket scientist.” - JB (little ones count!)

  6. #6
    Registered User
    Join Date
    05-07-2009
    Location
    Chesham,England
    MS-Off Ver
    Excel 2003 (11.5612.5606)
    Posts
    30

    Re: Calculate Button

    Hi,

    I do intend to clean up the missing data errors but at the moment I am concentrating on getting the program working which is now seriously complex,

    Currently the program occupies 61 sheets to produce the required data.

    Cheers for all the help it is very much appreciated!

  7. #7
    Forum Moderator shg's Avatar
    Join Date
    06-21-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2007
    Posts
    25,131

    Re: Calculate Button

    Currently the program occupies 61 sheets to produce the required data.
    That seems extraordinarily complex for anything short of designing nuclear weapons.
    Microsoft MVP - Excel
    Entia non sunt multiplicanda sine necessitate

  8. #8
    Registered User
    Join Date
    05-07-2009
    Location
    Chesham,England
    MS-Off Ver
    Excel 2003 (11.5612.5606)
    Posts
    30

    Re: Calculate Button

    Quote Originally Posted by shg View Post
    That seems extraordinarily complex for anything short of designing nuclear weapons.

    You should try being an electrician for a day!

  9. #9
    Forum Guru JBeaucaire's Avatar
    Join Date
    03-21-2008
    Location
    Bakersfield, CA
    MS-Off Ver
    2010
    Posts
    18,225

    Re: Calculate Button

    If that takes care of your need, be sure to EDIT your original post, click on GO ADVANCED and set the PREFIX box to [Solved].
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    “None of us is as good as all of us” - Ray Kroc
    “Actually, I *am* a rocket scientist.” - JB (little ones count!)

  10. #10
    Registered User
    Join Date
    06-21-2009
    Location
    Sydney
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Calculate Button

    Quote Originally Posted by shg View Post
    Create an AutoShape or Forms button, and assign this macro:
    Code:
    Sub Calc()
        Calculate
    End Sub
    Is there a code to do a calculate for just that sheet, ie. Shift + F9 ?

  11. #11
    Registered User
    Join Date
    08-16-2009
    Location
    Fort Smith, AR
    MS-Off Ver
    Excel 2003
    Posts
    14

    Re: Calculate Button

    Is there a code to do a calculate for just that sheet, ie. Shift + F9 ?
    Code:
     worksheet("Myworksheet").calculate

  12. #12
    Registered User
    Join Date
    06-21-2009
    Location
    Sydney
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Calculate Button

    Wonderful, many thanks !!!

  13. #13
    Registered User
    Join Date
    06-21-2009
    Location
    Sydney
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Calculate Button

    Quote Originally Posted by shua79 View Post
    Code:
     worksheet("Myworksheet").calculate
    I got the following error:

    "Compile error:
    Sub or Function not defined"

    This is the section of the code:

    ActiveSheet.Paste
    Worksheet("Expenses Input").Calculate
    Application.Run "'BUDGET.xls'!GO_Staff"


    EDIT
    Would this do the same thing?
    ActiveSheet.Calculate

  14. #14
    Forum Guru JBeaucaire's Avatar
    Join Date
    03-21-2008
    Location
    Bakersfield, CA
    MS-Off Ver
    2010
    Posts
    18,225

    Re: Calculate Button

    Two things:
    Code:
    Worksheets("Sheet2").Calculate
    Notice thats plural, worksheets.

    Second, the line of code
    Code:
    ActiveSheet.Paste
    ...implies you may be using .Select a bit in your code. Don't do that.

    One thing that has to be done is code you learn how to write using the macro recorder (which I still use most days) needs to be cleaned up afterward to remove all the unnecessary selecting. Post up your entire macro and we can make some suggestions.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    “None of us is as good as all of us” - Ray Kroc
    “Actually, I *am* a rocket scientist.” - JB (little ones count!)

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.2.0