Run macro when cell value changes

SQUIDD

Well-known Member
Joined
Jan 2, 2009
Messages
2,104
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
Hi All

I have tried to research this, but not found anything to work completly.

I want to clear some cells if a cells value changes, but the cells value is the result of a formula.

Posted below is what i have tried, but i get "out of stack space", so guess im looping continuesly.

im guessing actually the sheet caluclates again when i set it to 0??

VBA Code:
Private Sub Worksheet_Calculate()
    If Range("C38") = 1 Then
        Range("C28") = ""
        Range("E28:E33") = ""
        Range("C38") = 0
    End If
End Sub

thanks dave
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Have a try temporarily disabling events:
VBA Code:
Option Explicit
Private Sub Worksheet_Calculate()
    If Range("C38") = 1 Then
        Application.EnableEvents = False
        Range("C28") = ""
        Range("E28:E33") = ""
        Range("C38") = 0
        Application.EnableEvents = True
    End If
End Sub
 
Upvote 0
Hi rollis13

Genius mate, worked perfectly, so simple but very effective. Feel a little silly now LOL

thanks ver much

Dave
 
Upvote 0
Glad having been of some help (y).
But I'm not sure that the problem was create by C38=0, instead, probable by other formulas in other cells that dipend on it.
 
Upvote 0

Forum statistics

Threads
1,214,926
Messages
6,122,306
Members
449,079
Latest member
juggernaut24

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