PC Review


Reply
Thread Tools Rate Thread

Code Takes Forever to Run - Why?

 
 
BJ
Guest
Posts: n/a
 
      10th Nov 2008
I'm having difficulty with the following code. If I remove the first 'IF'
statement regarding the comparison to < 1500, it runs fine (ie, quickly), but
inserting it causes the routine to take about 1 minute to run ... forever in
my world ... and I can't figure out why it's causing such a delay.

I don't have to have the code built this way, but I've pulled it out into
it's ow separate section and the result - slow run time - persists.

Any help is greatly appreciated.

Brett

Private Sub Worksheet_Change(ByVal Target As Range)
With Me
If Intersect(Target, .Range("FROI_Vol"), .Range("SROI_Vol"),
..Range("MSR_Vol")) Is Nothing Then
If .Range("Total_Vol").Value < 1500 Then
.Range("AutoTrigger_Impl_Fee") = 0
Else
If .Range("Total_Vol").Value < 501 Or RenewProduct.Value = True Then
PT_Yes.Enabled = False
PT_No.Enabled = False
PT_No.Value = True
Else
PT_Yes.Enabled = True
PT_No.Enabled = True
PT_No.Value = True
End If
End If
End If
End With
 
Reply With Quote
 
 
 
 
Gary''s Student
Guest
Posts: n/a
 
      10th Nov 2008
Application.EnableEvents=False
..Range("AutoTrigger_Impl_Fee") = 0
Application.EnableEvents=True
--
Gary''s Student - gsnu200812


"BJ" wrote:

> I'm having difficulty with the following code. If I remove the first 'IF'
> statement regarding the comparison to < 1500, it runs fine (ie, quickly), but
> inserting it causes the routine to take about 1 minute to run ... forever in
> my world ... and I can't figure out why it's causing such a delay.
>
> I don't have to have the code built this way, but I've pulled it out into
> it's ow separate section and the result - slow run time - persists.
>
> Any help is greatly appreciated.
>
> Brett
>
> Private Sub Worksheet_Change(ByVal Target As Range)
> With Me
> If Intersect(Target, .Range("FROI_Vol"), .Range("SROI_Vol"),
> .Range("MSR_Vol")) Is Nothing Then
> If .Range("Total_Vol").Value < 1500 Then
> .Range("AutoTrigger_Impl_Fee") = 0
> Else
> If .Range("Total_Vol").Value < 501 Or RenewProduct.Value = True Then
> PT_Yes.Enabled = False
> PT_No.Enabled = False
> PT_No.Value = True
> Else
> PT_Yes.Enabled = True
> PT_No.Enabled = True
> PT_No.Value = True
> End If
> End If
> End If
> End With

 
Reply With Quote
 
BJ
Guest
Posts: n/a
 
      10th Nov 2008
gsnu

outstanding! thanks. in a nutshell can you educate me as to what i was
doing wrong and why the new code corrects works more efficiently?

bj

"Gary''s Student" wrote:

> Application.EnableEvents=False
> .Range("AutoTrigger_Impl_Fee") = 0
> Application.EnableEvents=True
> --
> Gary''s Student - gsnu200812
>
>
> "BJ" wrote:
>
> > I'm having difficulty with the following code. If I remove the first 'IF'
> > statement regarding the comparison to < 1500, it runs fine (ie, quickly), but
> > inserting it causes the routine to take about 1 minute to run ... forever in
> > my world ... and I can't figure out why it's causing such a delay.
> >
> > I don't have to have the code built this way, but I've pulled it out into
> > it's ow separate section and the result - slow run time - persists.
> >
> > Any help is greatly appreciated.
> >
> > Brett
> >
> > Private Sub Worksheet_Change(ByVal Target As Range)
> > With Me
> > If Intersect(Target, .Range("FROI_Vol"), .Range("SROI_Vol"),
> > .Range("MSR_Vol")) Is Nothing Then
> > If .Range("Total_Vol").Value < 1500 Then
> > .Range("AutoTrigger_Impl_Fee") = 0
> > Else
> > If .Range("Total_Vol").Value < 501 Or RenewProduct.Value = True Then
> > PT_Yes.Enabled = False
> > PT_No.Enabled = False
> > PT_No.Value = True
> > Else
> > PT_Yes.Enabled = True
> > PT_No.Enabled = True
> > PT_No.Value = True
> > End If
> > End If
> > End If
> > End With

 
Reply With Quote
 
Gary''s Student
Guest
Posts: n/a
 
      10th Nov 2008
Sure. The Worksheet_Change code responds to any changes in the worksheet.
We want it to respond to changes that the User types or pastes. We don't
want it to respond to changes that it makes. Otherwise we can get a long
series of re-entries into the routine.

So in general, if we want the sub to make changes in the sheet, we first
disable events, then makes the changes, then re-enable events.
--
Gary''s Student - gsnu200812


"BJ" wrote:

> gsnu
>
> outstanding! thanks. in a nutshell can you educate me as to what i was
> doing wrong and why the new code corrects works more efficiently?
>
> bj
>
> "Gary''s Student" wrote:
>
> > Application.EnableEvents=False
> > .Range("AutoTrigger_Impl_Fee") = 0
> > Application.EnableEvents=True
> > --
> > Gary''s Student - gsnu200812
> >
> >
> > "BJ" wrote:
> >
> > > I'm having difficulty with the following code. If I remove the first 'IF'
> > > statement regarding the comparison to < 1500, it runs fine (ie, quickly), but
> > > inserting it causes the routine to take about 1 minute to run ... forever in
> > > my world ... and I can't figure out why it's causing such a delay.
> > >
> > > I don't have to have the code built this way, but I've pulled it out into
> > > it's ow separate section and the result - slow run time - persists.
> > >
> > > Any help is greatly appreciated.
> > >
> > > Brett
> > >
> > > Private Sub Worksheet_Change(ByVal Target As Range)
> > > With Me
> > > If Intersect(Target, .Range("FROI_Vol"), .Range("SROI_Vol"),
> > > .Range("MSR_Vol")) Is Nothing Then
> > > If .Range("Total_Vol").Value < 1500 Then
> > > .Range("AutoTrigger_Impl_Fee") = 0
> > > Else
> > > If .Range("Total_Vol").Value < 501 Or RenewProduct.Value = True Then
> > > PT_Yes.Enabled = False
> > > PT_No.Enabled = False
> > > PT_No.Value = True
> > > Else
> > > PT_Yes.Enabled = True
> > > PT_No.Enabled = True
> > > PT_No.Value = True
> > > End If
> > > End If
> > > End If
> > > End With

 
Reply With Quote
 
Dana DeLouis
Guest
Posts: n/a
 
      12th Nov 2008
Hi. As a side note, I may have this wrong, so I'll just throw it our
for consideration.


>>> If .Range("Total_Vol").Value < 1500 Then
>>> .Range("AutoTrigger_Impl_Fee") = 0
>>> Else
>>> If .Range("Total_Vol").Value < 501 Or RenewProduct.Value = True...



It appears to me that if "Total_Vol" is say 499, or 500, then

the line <1500 gets executed, and the line with <501 never does.

Is this intentional?

- -
Dana DeLouis

(Also, since PT_No.Value = True is done either way, I think it could be
pulled out and listed only once.)


BJ wrote:
> gsnu
>
> outstanding! thanks. in a nutshell can you educate me as to what i was
> doing wrong and why the new code corrects works more efficiently?
>
> bj
>
> "Gary''s Student" wrote:
>
>> Application.EnableEvents=False
>> .Range("AutoTrigger_Impl_Fee") = 0
>> Application.EnableEvents=True
>> --
>> Gary''s Student - gsnu200812
>>
>>
>> "BJ" wrote:
>>
>>> I'm having difficulty with the following code. If I remove the first 'IF'
>>> statement regarding the comparison to < 1500, it runs fine (ie, quickly), but
>>> inserting it causes the routine to take about 1 minute to run ... forever in
>>> my world ... and I can't figure out why it's causing such a delay.
>>>
>>> I don't have to have the code built this way, but I've pulled it out into
>>> it's ow separate section and the result - slow run time - persists.
>>>
>>> Any help is greatly appreciated.
>>>
>>> Brett
>>>
>>> Private Sub Worksheet_Change(ByVal Target As Range)
>>> With Me
>>> If Intersect(Target, .Range("FROI_Vol"), .Range("SROI_Vol"),
>>> .Range("MSR_Vol")) Is Nothing Then
>>> If .Range("Total_Vol").Value < 1500 Then
>>> .Range("AutoTrigger_Impl_Fee") = 0
>>> Else
>>> If .Range("Total_Vol").Value < 501 Or RenewProduct.Value = True Then
>>> PT_Yes.Enabled = False
>>> PT_No.Enabled = False
>>> PT_No.Value = True
>>> Else
>>> PT_Yes.Enabled = True
>>> PT_No.Enabled = True
>>> PT_No.Value = True
>>> End If
>>> End If
>>> End If
>>> End With

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Vista Shutdown takes forever -- 10 min+ or forever =?Utf-8?B?RGF2ZVM=?= Windows Vista Performance 5 6th Apr 2007 09:54 PM
Detail Format code takes forever... RipperT Microsoft Access Reports 3 20th Dec 2006 09:56 PM
SP1 TAKES FOREVER Brian Jewell Windows XP General 1 23rd Apr 2004 02:34 PM
my desktop takes forever to load, sometimes 10-15 minuites, after the icons load every thing else takes forever. what's up with that =?Utf-8?B?bGFkeXR3ZWV0?= Windows XP General 1 8th Jan 2004 01:25 AM
This takes forever!!!!!!!! Helixpoint Microsoft ASP .NET 1 29th Jul 2003 07:53 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:26 AM.