Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default Code runs slooooww

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






  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default Code runs slooooww

try turning calculation off right after screenupdating

Application.Calculation = xlCalculationManual

and back on at the end

Application.Calculation = xlCalculationAutomatic

--


Gary


"GettingThere" wrote in message
...
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








  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default Code runs slooooww

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" wrote in message
...
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
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
vba code runs...need spaces ........ Wanna Learn Excel Discussion (Misc queries) 2 January 20th 09 12:44 PM
Code only runs once Kent Excel Programming 3 November 24th 05 03:47 PM
Code runs in 2002 but not in 97!? Big Chris[_39_] Excel Programming 4 August 25th 05 12:22 PM
Code runs every other time Mike Waldron Excel Programming 1 September 27th 03 03:54 PM
How to keep from going dizzy when my code runs TBA[_2_] Excel Programming 3 September 23rd 03 11:33 PM


All times are GMT +1. The time now is 02:47 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"