Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 67
Default SheetChange event starts before .calculate finished

Hi Nils,

Any idea how to force Excel to complete the calculation of the changed
range?


Try setting Application.Interactive = False before the .Calculate and
back to True afterwards.

Regards

Stephen Bullen
Microsoft MVP - Excel
www.BMSLtd.co.uk

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default SheetChange event starts before .calculate finished

Sorry Stephen, no effect: v=Target.value is still "0"

regards

Nils

Stephen Bullen wrote:
*Hi Nils,

Any idea how to force Excel to complete the calculation of the

changed
range?


Try setting Application.Interactive = False before the .Calculate
and
back to True afterwards.

Regards

Stephen Bullen
Microsoft MVP - Excel
www.BMSLtd.co.uk *

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 67
Default SheetChange event starts before .calculate finished

Hi Nils,

Sorry Stephen, no effect: v=Target.value is still "0"


OK, after a bit of investigation, I've managed to reproduce what you're seeing!

Am I correct in thinking that you have a complex workbook that takes some time to recalc and it's actually formulae that you're typing in that
you need to ensure are calculated correctly before writing their results to a database - so it's not the data entry that you're storing, but some
formulae results? And what you're finding is that continuing to type is automatically interrupting Excel's calculation?

There are two possible solutions to this issue (I think):

Solution 1 (tested):

Get Excel 2002 (in Office XP) and Application.CalculationInterruptKey = xlEscKey before Target.Calculate and Application.CalculationInterruptKey
= xlAnyKey afterwards. This is a new property added to Excel 2002 specifically to control when/if calculation can be interrupted.

Solution 2 (untested):

A. Use API Calls to see if there's anything in the Windows keyboard buffer (see checkkey.zip on my web site), store them and remove them.
B. Set Application.Interaction = False, do the Calc and set it back to true
C. Use SendKeys to put the keystrokes stored in A. back in the buffer

Regards

Stephen Bullen
Microsoft MVP - Excel
www.BMSLtd.co.uk

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 67
Default SheetChange event starts before .calculate finished

Hi Nils,

Regarding solution 2 you may provide me with some additional
information. I see in your example (checkkey) how to look if a key is
pressed (although I don't know how the API works). How do I remove the
key from the buffer before the calculation is interupted? I haven't
writen such an interrup handler.


Don't bother - it didn't work!

How about using:

v = Application.Evaluate(Target.Formula)

instead of forcing the Target.Calculate that gets interrupted?

Regards

Stephen Bullen
Microsoft MVP - Excel
www.BMSLtd.co.uk

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default SheetChange event starts before .calculate finished

Hi Stephen,

Congratulations! Thats excactly the thing I wanted to do when I talked
about getting the result of the .Formula without taking .value. And it
seems to work. You only have to check if .formula is filled before you
can do it. Otherwise you get an error when cell content is deleted.

My code now looks like the following and after the first test it seems
to be ok.

Thanks a lot,

regards

Nils.

For Each i In target

If i.Formula = "" Then
v = i.Value
Else
v = Application.Evaluate(i.Formula)
End If
...
Next i

Stephen Bullen wrote:
*Hi Nils,

Regarding solution 2 you may provide me with some additional
information. I see in your example (checkkey) how to look if a key

is
pressed (although I don't know how the API works). How do I remove

the
key from the buffer before the calculation is interupted? I

haven't
writen such an interrup handler.


Don't bother - it didn't work!

How about using:

v = Application.Evaluate(Target.Formula)

instead of forcing the Target.Calculate that gets interrupted?

Regards

Stephen Bullen
Microsoft MVP - Excel
www.BMSLtd.co.uk *




------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from http://www.ExcelForum.com/



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default SheetChange event starts before .calculate finished

Maybe:
if i.hasformula then

would be safer.

(pretty interesting thread, too.)



Nils M wrote:

In addition to my last response where I rashly said that it works there
seems to be a bug in Excel:

The code:

v = Application.Evaluate(i.Formula)

produce a run time error for i.Formula="1"! All other values/formulas
are accepted even "=2-1". Strange but this is Excel ;-)

My code now looks like

If Left(i.Formula, 1) = "=" Then
v = Application.Evaluate(i.Formula)
Else
v = i.Value
End If

regards,

Nils

------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from http://www.ExcelForum.com/


--

Dave Peterson

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel E-2007 starts, but Installer also starts 3 times??? Thanks for the Great Tip Setting up and Configuration of Excel 0 January 24th 10 03:21 AM
calculate from time started and finished to get total time used Novice-Sandra Excel Worksheet Functions 2 June 21st 08 04:31 PM
Please Help: Macro Nearly Finished Dave Excel Discussion (Misc queries) 1 September 20th 07 12:16 PM
Turn off calculate event nobbyknownowt Excel Discussion (Misc queries) 4 July 5th 06 10:51 AM
SheetChange event starts before .calculate finished Dave Peterson[_3_] Excel Programming 2 September 9th 03 08:49 AM


All times are GMT +1. The time now is 05:52 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"