where "H5" is the particular cell being monitored and Macro is the name of the macro.
Is there a better way?
回答1:
Your code looks pretty good.
Be careful, however, for your call to Range("H5") is a shortcut command to Application.Range("H5"), which is equivalent to Application.ActiveSheet.Range("H5"). This could be fine, if the only changes are user-changes -- which is the most typical -- but it is possible for the worksheet's cell values to change when it is not the active sheet via programmatic changes, e.g. VBA.
With this in mind, I would utilize Target.Worksheet.Range("H5"):
I have a cell which is linked to online stock database and updated frequently. I want to trigger a macro whenever the cell value is updated.
I believe this is similar to cell value change by a program or any external data update but above examples somehow do not work for me. I think the problem is because excel internal events are not triggered, but thats my guess.
I did the following,
PrivateSubWorksheet_Change(ByValTargetAsRange)IfNotIntersect(Target,Target.Worksheets("Symbols").Range("$C$3"))IsNothingThen'Run Macro End Sub