What code do in need to run a macro any time the value of a cell changes?
What code do in need to run a macro any time the value of a cell changes?
Last edited by Pony08; 01-05-2016 at 03:26 PM.
You could try something like this perhaps
Alf![]()
Private Sub Worksheet_Change(ByVal Target As Range) If Not Intersect(Range(“YourCellAddress”), Target) Is Nothing Then Run your macro End If End Sub
Thx! That works well if I type in a new number...I have a macro that I want to run if a cells that has a formula in it...and the results from the formula changes...I think the fact that the formula stays the same, the macro will not run until I overwrite the formula with just a number.
Thoughts?
Well if the change is based on a formula then you could try this:
Right click on the sheet tab where the cell is you want to capture a change in. Click "View Code" and paste this code in the window. Say it's sheet1
Then to the left in the Visual Basic Window you see a number of work sheets and "ThisWorkbook".![]()
Private Sub Worksheet_Calculate() If Range("B4").Value <> PrevVal Then ' Run Macro End If End Sub
Right click on "ThisWorkbook" and paste this code in the new window.
Save file and open it again. Now try to update you formula target cell and see if macro runs.![]()
Private Sub Workbook_Open() PrevVal = Sheet1.Range("B4").Value End Sub
Alf
That worked great Alf...thanks for all your help!!!
You are welcome.
Thanks for feedback.
Alf
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks