Welcome to the Excel Forum

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed.

Please Register to Remove these Ads

Please Register to Remove these Ads



Reply
  #1  
Old 07-04-2009, 03:20 PM
martynduerden martynduerden is offline
Registered User
 
Join Date: 07 May 2009
Location: Chesham,England
MS Office Version:Excel 2003 (11.5612.5606)
Posts: 28
martynduerden is becoming part of the community
Calculate Button

Please Register to Remove these Ads

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
Reply With Quote
  #2  
Old 07-04-2009, 03:31 PM
shg's Avatar
shg shg is online now
Forum Guru
 
Join Date: 21 Jun 2007
Location: The Great State of Texas
MS Office Version:2003, 2007
Posts: 17,874
shg makes giving solutions look like childsplay shg makes giving solutions look like childsplay shg makes giving solutions look like childsplay shg makes giving solutions look like childsplay shg makes giving solutions look like childsplay shg makes giving solutions look like childsplay shg makes giving solutions look like childsplay shg makes giving solutions look like childsplay shg makes giving solutions look like childsplay
Re: Calculate Button

Create an AutoShape or Forms button, and assign this macro:
Code:
Sub Calc()
    Calculate
End Sub
__________________
Entia non sunt multiplicanda sine necessitate.
Reply With Quote
  #3  
Old 07-04-2009, 03:39 PM
JBeaucaire's Avatar
JBeaucaire JBeaucaire is online now
Forum Guru
 
Join Date: 21 Mar 2008
Location: Bakersfield, CA
MS Office Version:2003 (can read 2007 files)
Posts: 8,415
JBeaucaire makes giving solutions look like childsplay JBeaucaire makes giving solutions look like childsplay JBeaucaire makes giving solutions look like childsplay JBeaucaire makes giving solutions look like childsplay JBeaucaire makes giving solutions look like childsplay JBeaucaire makes giving solutions look like childsplay JBeaucaire makes giving solutions look like childsplay JBeaucaire makes giving solutions look like childsplay JBeaucaire makes giving solutions look like childsplay
Send a message via Skype™ to JBeaucaire
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.
__________________
“Actually, I *am* a rocket scientist.” - JB (little ones count!)
“None of us is as good as all of us” - Ray Kroc
Always put your code between [code] and [/code] tags.
Reply With Quote
  #4  
Old 07-04-2009, 03:55 PM
martynduerden martynduerden is offline
Registered User
 
Join Date: 07 May 2009
Location: Chesham,England
MS Office Version:Excel 2003 (11.5612.5606)
Posts: 28
martynduerden is becoming part of the community
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.
Reply With Quote
  #5  
Old 07-04-2009, 08:28 PM
JBeaucaire's Avatar
JBeaucaire JBeaucaire is online now
Forum Guru
 
Join Date: 21 Mar 2008
Location: Bakersfield, CA
MS Office Version:2003 (can read 2007 files)
Posts: 8,415
JBeaucaire makes giving solutions look like childsplay JBeaucaire makes giving solutions look like childsplay JBeaucaire makes giving solutions look like childsplay JBeaucaire makes giving solutions look like childsplay JBeaucaire makes giving solutions look like childsplay JBeaucaire makes giving solutions look like childsplay JBeaucaire makes giving solutions look like childsplay JBeaucaire makes giving solutions look like childsplay JBeaucaire makes giving solutions look like childsplay
Send a message via Skype™ to JBeaucaire
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.

Quote:
...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.
__________________
“Actually, I *am* a rocket scientist.” - JB (little ones count!)
“None of us is as good as all of us” - Ray Kroc
Always put your code between [code] and [/code] tags.
Reply With Quote
  #6  
Old 07-04-2009, 08:35 PM
martynduerden martynduerden is offline
Registered User
 
Join Date: 07 May 2009
Location: Chesham,England
MS Office Version:Excel 2003 (11.5612.5606)
Posts: 28
martynduerden is becoming part of the community
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!
Reply With Quote
  #7  
Old 07-04-2009, 08:39 PM
shg's Avatar
shg shg is online now
Forum Guru
 
Join Date: 21 Jun 2007
Location: The Great State of Texas
MS Office Version:2003, 2007
Posts: 17,874
shg makes giving solutions look like childsplay shg makes giving solutions look like childsplay shg makes giving solutions look like childsplay shg makes giving solutions look like childsplay shg makes giving solutions look like childsplay shg makes giving solutions look like childsplay shg makes giving solutions look like childsplay shg makes giving solutions look like childsplay shg makes giving solutions look like childsplay
Re: Calculate Button

Quote:
Currently the program occupies 61 sheets to produce the required data.
That seems extraordinarily complex for anything short of designing nuclear weapons.
__________________
Entia non sunt multiplicanda sine necessitate.
Reply With Quote
  #8  
Old 07-04-2009, 08:48 PM
martynduerden martynduerden is offline
Registered User
 
Join Date: 07 May 2009
Location: Chesham,England
MS Office Version:Excel 2003 (11.5612.5606)
Posts: 28
martynduerden is becoming part of the community
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!
Reply With Quote
  #9  
Old 07-05-2009, 02:18 PM
JBeaucaire's Avatar
JBeaucaire JBeaucaire is online now
Forum Guru
 
Join Date: 21 Mar 2008
Location: Bakersfield, CA
MS Office Version:2003 (can read 2007 files)
Posts: 8,415
JBeaucaire makes giving solutions look like childsplay JBeaucaire makes giving solutions look like childsplay JBeaucaire makes giving solutions look like childsplay JBeaucaire makes giving solutions look like childsplay JBeaucaire makes giving solutions look like childsplay JBeaucaire makes giving solutions look like childsplay JBeaucaire makes giving solutions look like childsplay JBeaucaire makes giving solutions look like childsplay JBeaucaire makes giving solutions look like childsplay
Send a message via Skype™ to JBeaucaire
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].
__________________
“Actually, I *am* a rocket scientist.” - JB (little ones count!)
“None of us is as good as all of us” - Ray Kroc
Always put your code between [code] and [/code] tags.
Reply With Quote
  #10  
Old 08-17-2009, 12:06 AM
philosman philosman is offline
Registered User
 
Join Date: 21 Jun 2009
Location: Sydney
MS Office Version:Excel 2003
Posts: 7
philosman is becoming part of the community
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 ?
Reply With Quote
  #11  
Old 08-17-2009, 12:38 AM
shua79 shua79 is offline
Registered User
 
Join Date: 16 Aug 2009
Location: Fort Smith, AR
MS Office Version:Excel 2003
Posts: 14
shua79 is becoming part of the community
Re: Calculate Button

Quote:
Is there a code to do a calculate for just that sheet, ie. Shift + F9 ?
Code:
 worksheet("Myworksheet").calculate
Reply With Quote
  #12  
Old 08-17-2009, 02:34 AM
philosman philosman is offline
Registered User
 
Join Date: 21 Jun 2009
Location: Sydney
MS Office Version:Excel 2003
Posts: 7
philosman is becoming part of the community
Re: Calculate Button

Wonderful, many thanks !!!
Reply With Quote
  #13  
Old 08-17-2009, 07:07 AM
philosman philosman is offline
Registered User
 
Join Date: 21 Jun 2009
Location: Sydney
MS Office Version:Excel 2003
Posts: 7
philosman is becoming part of the community
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
Reply With Quote
  #14  
Old 08-17-2009, 11:58 AM
JBeaucaire's Avatar
JBeaucaire JBeaucaire is online now
Forum Guru
 
Join Date: 21 Mar 2008
Location: Bakersfield, CA
MS Office Version:2003 (can read 2007 files)
Posts: 8,415
JBeaucaire makes giving solutions look like childsplay JBeaucaire makes giving solutions look like childsplay JBeaucaire makes giving solutions look like childsplay JBeaucaire makes giving solutions look like childsplay JBeaucaire makes giving solutions look like childsplay JBeaucaire makes giving solutions look like childsplay JBeaucaire makes giving solutions look like childsplay JBeaucaire makes giving solutions look like childsplay JBeaucaire makes giving solutions look like childsplay
Send a message via Skype™ to JBeaucaire
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.
__________________
“Actually, I *am* a rocket scientist.” - JB (little ones count!)
“None of us is as good as all of us” - Ray Kroc
Always put your code between [code] and [/code] tags.
Reply With Quote


Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Forum Jump