Worksheet_Calculate or Worksheet_Change?

liampog

Active Member
Joined
Aug 3, 2010
Messages
316
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hi there

I'm trying to run some code when the cell value changes to particular values.

However, the cells being monitored are protected cells that changing depending on an IF statement. The example below is the IF formula in the C2 cell:

Code:
=IF(C10="","",IF(AND(C10>"07:00",C10<"18:00"),C10,""))

I want a number of functions to run when the text in the cell changes to certain values depending on the result of the IF statement.

Do I use Worksheet_Calculate for this, or Worksheet_Change?

Can somebody give me some example code that might be a solution to this?

Thanks,
Liam
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
You need the calculate event as the change event is not triggered by formula calculations - or you can use the change event but monitor changes to cell C10 (assuming that's not also a formula)
 
Upvote 0
You can use either...

The Calculate event will trigger when the result of a formula changes.
However, you can't capture what caused the formula to change, or even which formula changed.


You can also use the Change event.
But instead of monitoring the cell containing the formula,
you make it monitor the cells that the formula refers to.
Which in your example, would be C10


Hope that helps.
 
Last edited:
Upvote 0
Try like this

Code:
Private Sub Worksheet_Calculate()
Static OldVal As Variant
If Range("A1").Value <> OldVal Then
    OldVal = Range("A1").Value
    '
    ' do something
    '
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,570
Messages
6,179,610
Members
452,931
Latest member
The Monk

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top