Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 59
Default Why does this Worksheet Calculate Event run so slow?

I'm trying to create a validation macro to enter text into the cell of range
G:G depending on the contents of the adjacent cells in columns C and D. This
is what I have done to start with, there are other ElseIf entries to be
added, but it is really slow to start with.

Private Sub Worksheet_Calculate()
Dim myC As Range
Dim WatchRange1 As Range

With Application
.ScreenUpdating = False
.Calculation = xlCalculationManual
End With

Set WatchRange1 = Range("G2:G500")

For Each myC In WatchRange1

If myC.Offset(0, -3).Value = "Contract1" And _
myC.Offset(0, -4).Value = "Status A" Then
myC.Cells.Value = "Response A"
ElseIf myC.Offset(0, -3).Value = "Contract 2" And _
myC.Offset(0, -4).Value = "Status A" Then
myC.Cells.Value = "Response B"
Else: myC.Cells.Value = ""
End If

Next myC

With Application
.ScreenUpdating = True
.Calculation = xlCalculationAutomatic
End With
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default Why does this Worksheet Calculate Event run so slow?

Putting into a calculate event calculates everything. I would write a bit
differently using cells(

for i= 2 to cells(rows.count,"g").end(xlup).row
if cells(i,"c")="sa" and cells(i,"d")="c1" then cells(i,"g")="aa"
if cells(i,"c")="sa" and cells(i,"d")="c2" then cells(i,"g")="bb"
if cells(i,"c")="sb" and cells(i,"d")="c1" then cells(i,"g")="aa1"
..etc with ONE line IFs with NO end if required for one liners
next i

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"DDawson" wrote in message
...
I'm trying to create a validation macro to enter text into the cell of
range
G:G depending on the contents of the adjacent cells in columns C and D.
This
is what I have done to start with, there are other ElseIf entries to be
added, but it is really slow to start with.

Private Sub Worksheet_Calculate()
Dim myC As Range
Dim WatchRange1 As Range

With Application
.ScreenUpdating = False
.Calculation = xlCalculationManual
End With

Set WatchRange1 = Range("G2:G500")

For Each myC In WatchRange1

If myC.Offset(0, -3).Value = "Contract1" And _
myC.Offset(0, -4).Value = "Status A" Then
myC.Cells.Value = "Response A"
ElseIf myC.Offset(0, -3).Value = "Contract 2" And _
myC.Offset(0, -4).Value = "Status A" Then
myC.Cells.Value = "Response B"
Else: myC.Cells.Value = ""
End If

Next myC

With Application
.ScreenUpdating = True
.Calculation = xlCalculationAutomatic
End With
End Sub


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Why does this Worksheet Calculate Event run so slow?

Use the worksheet Change event rather than the Calculate event. Target will
allow you to examine only a single pair of cells rather than all the pairs of
cells.
--
Gary''s Student - gsnu200769


"DDawson" wrote:

I'm trying to create a validation macro to enter text into the cell of range
G:G depending on the contents of the adjacent cells in columns C and D. This
is what I have done to start with, there are other ElseIf entries to be
added, but it is really slow to start with.

Private Sub Worksheet_Calculate()
Dim myC As Range
Dim WatchRange1 As Range

With Application
.ScreenUpdating = False
.Calculation = xlCalculationManual
End With

Set WatchRange1 = Range("G2:G500")

For Each myC In WatchRange1

If myC.Offset(0, -3).Value = "Contract1" And _
myC.Offset(0, -4).Value = "Status A" Then
myC.Cells.Value = "Response A"
ElseIf myC.Offset(0, -3).Value = "Contract 2" And _
myC.Offset(0, -4).Value = "Status A" Then
myC.Cells.Value = "Response B"
Else: myC.Cells.Value = ""
End If

Next myC

With Application
.ScreenUpdating = True
.Calculation = xlCalculationAutomatic
End With
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
How to determine the worksheet that a calculate event gets initiated on when the workbook is not active Riddler Excel Programming 2 May 16th 07 01:58 PM
Change event and calculate event Antje Excel Programming 1 March 29th 05 09:03 PM
Event Procedures: Event on Worksheet to fire Event on another Worksheet Kathryn Excel Programming 2 April 7th 04 07:35 PM
Worksheet Calculate Event Gustavo[_4_] Excel Programming 2 January 14th 04 09:00 PM


All times are GMT +1. The time now is 01:07 PM.

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

About Us

"It's about Microsoft Excel"