PC Review


Reply
Thread Tools Rate Thread

Code runs slooooww

 
 
=?Utf-8?B?R2V0dGluZ1RoZXJl?=
Guest
Posts: n/a
 
      14th Dec 2006
The following code takes many, many minutes to run on several hundred rows.
Does anyone have any suggestions that might speed it up?

Thanks in advance!

Option Explicit

Sub tester()
Dim i As Long
Dim area As String
Dim c As Range
Const sked = "0:30"

Application.ScreenUpdating = False

For i = 3 To Cells(Rows.Count, "C").End(xlUp).Row Step 1

If Cells(i, 1).Value <> "CT" Then

area = Cells(i, "D").Value

Select Case area
Case "CR1"
For Each c In Range(Cells(i, "u"), Cells(i, "bg"))
If c.Text Like sked Then
c.Value = "CR1"
Else
c.Value = "X"
End If
Next c

Case "CR2", "CR3"
If Cells(i, "E").Value Like "*CR1*" Then
For Each c In Range(Cells(i, "u"), Cells(i, "bg"))
If c.Text Like sked Then
c.Value = "OTH"
Else
c.Value = "X"
End If
Next c
Else
Range(Cells(i, "u"), Cells(i, "bg")).Value = "X"
End If
Case Else
Cells(i, "U").Value = "X"

End Select

Else
Range(Cells(i, "u"), Cells(i, "BG")).Value = "X"
' GO TO NEXT

End If

Next i
End Sub






 
Reply With Quote
 
 
 
 
Gary Keramidas
Guest
Posts: n/a
 
      14th Dec 2006
try turning calculation off right after screenupdating

Application.Calculation = xlCalculationManual

and back on at the end

Application.Calculation = xlCalculationAutomatic

--


Gary


"GettingThere" <(E-Mail Removed)> wrote in message
news:4EB37DEB-1CFA-4767-9B10-(E-Mail Removed)...
> The following code takes many, many minutes to run on several hundred rows.
> Does anyone have any suggestions that might speed it up?
>
> Thanks in advance!
>
> Option Explicit
>
> Sub tester()
> Dim i As Long
> Dim area As String
> Dim c As Range
> Const sked = "0:30"
>
> Application.ScreenUpdating = False
>
> For i = 3 To Cells(Rows.Count, "C").End(xlUp).Row Step 1
>
> If Cells(i, 1).Value <> "CT" Then
>
> area = Cells(i, "D").Value
>
> Select Case area
> Case "CR1"
> For Each c In Range(Cells(i, "u"), Cells(i, "bg"))
> If c.Text Like sked Then
> c.Value = "CR1"
> Else
> c.Value = "X"
> End If
> Next c
>
> Case "CR2", "CR3"
> If Cells(i, "E").Value Like "*CR1*" Then
> For Each c In Range(Cells(i, "u"), Cells(i, "bg"))
> If c.Text Like sked Then
> c.Value = "OTH"
> Else
> c.Value = "X"
> End If
> Next c
> Else
> Range(Cells(i, "u"), Cells(i, "bg")).Value = "X"
> End If
> Case Else
> Cells(i, "U").Value = "X"
>
> End Select
>
> Else
> Range(Cells(i, "u"), Cells(i, "BG")).Value = "X"
> ' GO TO NEXT
>
> End If
>
> Next i
> End Sub
>
>
>
>
>
>



 
Reply With Quote
 
=?Utf-8?B?R2V0dGluZ1RoZXJl?=
Guest
Posts: n/a
 
      15th Dec 2006
Thanks Gary - that did the trick. It's funny because I had done this very
thing in a different part of the module, but I didn't think it would do any
good here since I'm not working with formulas. Learn something new every day
: )

"Gary Keramidas" wrote:

> try turning calculation off right after screenupdating
>
> Application.Calculation = xlCalculationManual
>
> and back on at the end
>
> Application.Calculation = xlCalculationAutomatic
>
> --
>
>
> Gary
>
>
> "GettingThere" <(E-Mail Removed)> wrote in message
> news:4EB37DEB-1CFA-4767-9B10-(E-Mail Removed)...
> > The following code takes many, many minutes to run on several hundred rows.
> > Does anyone have any suggestions that might speed it up?
> >
> > Thanks in advance!
> >
> > Option Explicit
> >
> > Sub tester()
> > Dim i As Long
> > Dim area As String
> > Dim c As Range
> > Const sked = "0:30"
> >
> > Application.ScreenUpdating = False
> >
> > For i = 3 To Cells(Rows.Count, "C").End(xlUp).Row Step 1
> >
> > If Cells(i, 1).Value <> "CT" Then
> >
> > area = Cells(i, "D").Value
> >
> > Select Case area
> > Case "CR1"
> > For Each c In Range(Cells(i, "u"), Cells(i, "bg"))
> > If c.Text Like sked Then
> > c.Value = "CR1"
> > Else
> > c.Value = "X"
> > End If
> > Next c
> >
> > Case "CR2", "CR3"
> > If Cells(i, "E").Value Like "*CR1*" Then
> > For Each c In Range(Cells(i, "u"), Cells(i, "bg"))
> > If c.Text Like sked Then
> > c.Value = "OTH"
> > Else
> > c.Value = "X"
> > End If
> > Next c
> > Else
> > Range(Cells(i, "u"), Cells(i, "bg")).Value = "X"
> > End If
> > Case Else
> > Cells(i, "U").Value = "X"
> >
> > End Select
> >
> > Else
> > Range(Cells(i, "u"), Cells(i, "BG")).Value = "X"
> > ' GO TO NEXT
> >
> > End If
> >
> > Next i
> > End Sub
> >
> >
> >
> >
> >
> >

>
>
>

 
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
Report "open" code runs - header format code doesn't TomM Microsoft Access 1 27th Nov 2008 01:38 AM
Code only runs once =?Utf-8?B?S2VudA==?= Microsoft Excel Programming 3 24th Nov 2005 03:47 PM
Code Runs Twice DS Microsoft Access Getting Started 1 25th Oct 2005 05:16 PM
Re: win2K running slooooww... Mark-Allen Microsoft Windows 2000 0 27th Jul 2004 07:07 PM
Re: win2K running slooooww... Walter Donavan Microsoft Windows 2000 0 27th Jul 2004 06:51 PM


Features
 

Advertising
 

Newsgroups
 


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