G
Greg P
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,
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,