Forum Discussion
Th0r_L13n
Jul 08, 2021Copper Contributor
VBA code for triggering a macro based on change in cell with formula
I'm trying to get a macro to run based on a change in value in a cell, but the cell contains with a formula so the standard trigger on value does not work. Any suggestions ?
HansVogelaar
Jul 08, 2021MVP
The best option is to check the cells that determine the result of the formula and that are directly changed by the user.
A very simple example: let's say that cell A10 contains the formula =SUM(A2:A9), and that A2:A9 are filled by the user. Instead of checking A10, check A2:A9:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Range("A2:A9"), Target) Is Nothing Them
...
End If
End Sub
Alternatively, you could use the Worksheet_Calculate event. This will cause a lot of overhead, though, for this event does not have a Target argument. So the code will run every time any cell on the sheet is recalculated.
Th0r_L13n
Jul 08, 2021Copper Contributor
The problem is that the formula comes from a external feed, and not a sum or so from other cells
- Th0r_L13nJul 08, 2021Copper Contributorexample :
=QueryJoule("Italy Baseload - All Venues", "", "1", "bid price", "1", "Quarters")
and the feed ends up to be a number- HansVogelaarJul 08, 2021MVP
You'll have to use the Worksheet_Calculate event.