Which workbook caused calculation

M

Mark Driscol

I have a workbook "A" that uses the worksheet_calculate event in a
sheet. Working in other workbooks triggers the event from time to
time, and I'd like to be able to modify the event code to detect that
calculation was not triggered by working in "A" and exit.

Is this possible?

Thanks.

Mark
 
S

salgud

I have a workbook "A" that uses the worksheet_calculate event in a
sheet. Working in other workbooks triggers the event from time to
time, and I'd like to be able to modify the event code to detect that
calculation was not triggered by working in "A" and exit.

Is this possible?

Thanks.

Mark

One way to do that is to set a public boolean variable (like bWSA maybe) to
true whenever Worksheet A is activated, then reset it to false when A is
deactivated. Then check the value of bWSA when the worksheet_calculate
event is triggered, like

If bWSA = true then
call yoursub
End if

Something like that. The many experts here may have simpler, or more
complex, solutions.
 
M

Mark

One way to do that is to set a public boolean variable (like bWSA maybe) to
true whenever Worksheet A is activated, then reset it to false when A is
deactivated. Then check the value of bWSA when the worksheet_calculate
event is triggered, like

If bWSA = true then
call yoursub
End if

Something like that. The many experts here may have simpler, or more
complex, solutions.

Thank you, I'll try that.

Mark
 
P

Patrick Molloy

you could code the ThisWorkbook event

Private Sub Workbook_SheetCalculate(ByVal Sh As Object)

End Sub
 
S

Simon Murphy

I try and avoid using the calc event for just this reason.

You could put something like this at the top of your event code

if activeworkbook.name = thisworkbook.name then
do your stuff
Else
do nothing
end if/ end sub

That will effectively turn your code off whenever the workbook it is in
is not the active one.

Cheers
Simon
Excel development website: www.codematic.net
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top