macro-vba execute question

ottasight

New Member
Joined
Feb 15, 2009
Messages
47
Hi
is there a way for the worksheet to run a macro/vba code on auto-calculation iteration, rather than through an interactive object like a button..............thanks
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Hi Smitty
how do i use that. do i type "hth" in a cell then name the macro?
i.e. hth, printselectrange.........thanks
 
Upvote 0
Hi,
Smitty's 'HTH' simply stands for "Hope This Helps." It really has nothing to do with your answer.

What he's referring to is going into your sheet code module (right click the sheet tab & choose View Code), and putting your code into the Worksheet_Calculate event. Then it will get called every time your sheet calculates.

Does that help at all?
 
Upvote 0
thanks HalfAce
but not quite sure what "calculate event" is. if calculate event is in vba code how is it assigned to to run in a cell to get auto-calculated, since the code is run by button or something, what would i write in a cell. i.e. "run,"sub,printwhatever""...........thanks
 
Upvote 0
Event code is code that gets executed in response to events that take place on your worksheet (or UserForm or ActiveX controls when used within those contexts). Code inside the Calculate event procedure runs whenever the worksheet is recalculated. Anyway, event code is installed in a different location than macro (event code is placed in the sheet module to which it applies as opposed to a standard module used for macros). Also, cell references could be different in event code depending on which event is being used and what the code is doing, so it is kind of hard to give you a general solution without know what your code looks like. Can you post your current macro and provide enough description with it about your data layout and what your code is supposed to be doing with that data?
 
Upvote 0
Here's an example of a Calculate event:

Code:
Private Sub Worksheet_Calculate()
    MsgBox "Sheet just calculated"
End Sub

If you put a formula in a cell, like =A1, then change A1 the Message Box should appear.

EDIT: I was on the phone and missed Rick's response. And yes, to confirm what Dan said, "HTH" means "Hope that helps" :)
 
Upvote 0
Thanks Guys
i think i'm getting it. the worksheet module incorporates the code into the worksheet itself. but still have question. what is " Worksheet_calculate event". is that what the module does or is that something i need to type into the module.......thanks
 
Upvote 0
Yes, you put the event code in a module.

Code:
Private Sub Worksheet_Calculate()
    MsgBox "Sheet just calculated"
End Sub

That is an example of a Calculate event, and the code itself goes in the worksheet specific module, not a general module. You don't need to do anything for it to fire, other than a mechanism for your formulas to fire, like changing the value in a dependent cell.
 
Upvote 0

Forum statistics

Threads
1,224,564
Messages
6,179,547
Members
452,925
Latest member
duyvmex

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top