![]() |
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 |
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 |
All times are GMT +1. The time now is 12:34 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com