Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Working with Calculate Event

I am using this if statement in 5 sheets calculate event:

Private Sub Worksheet_Calculate()
If Range("IdleG").Value < 0 Then
blnGFlag = True 'change this if you add one to go back positive
Range("NoOfG").Value = Range("NoOfG").Value + 1
Else
'handles if you are greater than zero and not just moved above it
'avoid div by 0
If Range("IdleG") 0 And blnGFlag < True And Range("NoOfG") < 1
Then
Range("NoOfG").Value = Range("NoOfG").Value - 1
End If
End If
End Sub

The blnNFlag is a global variable declared in a code module. What I am
attempting to do here is test if Idle time is positive remove one more
processor and check if it is still positive, until it goes negative. Then I
add one back on and throw a flag that tells me not to subract any more, thus
determining how many processors are needed.

That works, THE PROBLEM IS resetting my blnNFlag after the five differnt
sheets calculate event have been performed. Every time I add or subtract one
processor the event calculate event is called again, this is acting as a do
while loop for me. So it has to run through each sheets event many times,
and If I reset the blnNFlag before the last itereation, the second if test:

If Range("IdleG") 0 And blnGFlag < True And Range("NoOfG") < 1 Then

will be entered and an endless loop is created. Is there some after
calculate event? Or some ideas on how to reset my flags? I was thinking
maybe the worksheet calculated event? If I could then control how many time
the flags are reset? Or if I could reset the flags before each calcualte, so
a before_calculate event that would work also?

Thanks for your time,


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Working with Calculate Event

To create a psuedo after calculate event I just used a global variable to
count the number of if loops I entered and another variable to count the
number of if loops I exiteded. At the end of each calculate event I tested
to see if they were the same number (all iterations finsihed) and if so
called my module. This worked really well and could be useful to others.

Greg

"Greg P" wrote:

I am using this if statement in 5 sheets calculate event:

Private Sub Worksheet_Calculate()
If Range("IdleG").Value < 0 Then
blnGFlag = True 'change this if you add one to go back positive
Range("NoOfG").Value = Range("NoOfG").Value + 1
Else
'handles if you are greater than zero and not just moved above it
'avoid div by 0
If Range("IdleG") 0 And blnGFlag < True And Range("NoOfG") < 1
Then
Range("NoOfG").Value = Range("NoOfG").Value - 1
End If
End If
End Sub

The blnNFlag is a global variable declared in a code module. What I am
attempting to do here is test if Idle time is positive remove one more
processor and check if it is still positive, until it goes negative. Then I
add one back on and throw a flag that tells me not to subract any more, thus
determining how many processors are needed.

That works, THE PROBLEM IS resetting my blnNFlag after the five differnt
sheets calculate event have been performed. Every time I add or subtract one
processor the event calculate event is called again, this is acting as a do
while loop for me. So it has to run through each sheets event many times,
and If I reset the blnNFlag before the last itereation, the second if test:

If Range("IdleG") 0 And blnGFlag < True And Range("NoOfG") < 1 Then

will be entered and an endless loop is created. Is there some after
calculate event? Or some ideas on how to reset my flags? I was thinking
maybe the worksheet calculated event? If I could then control how many time
the flags are reset? Or if I could reset the flags before each calcualte, so
a before_calculate event that would work also?

Thanks for your time,


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 225
Default Working with Calculate Event

Hi Greg,

Thanks for your quickly reply!
It seems that you have found the workaround, If I misunderstood, please let
me know.
BTW:
I think you may try to disable the event temporarily when you did not want
the event fire.
Sub Test()
Application.EnableEvents = False
Range("D1").Text = "Test"
Application.EnableEvents = True
End Sub

Best regards,

Peter Huang

Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

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
Calculate working days but change working week SamB Excel Discussion (Misc queries) 1 September 1st 08 09:17 PM
Calculate Event Martin Bauer Excel Programming 6 April 14th 06 08:43 AM
Change event and calculate event Antje Excel Programming 1 March 29th 05 09:03 PM
AFTER Calculate Event PosseJohn Excel Programming 4 January 16th 05 07:31 PM


All times are GMT +1. The time now is 08:49 PM.

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

About Us

"It's about Microsoft Excel"