Detect Autofilter changes

后端 未结 2 1574
花落未央
花落未央 2021-01-16 00:40

I am looking to detect any changes in an autofilter on a specific table, for the purpose of forcing a UDF that does some simple arithmetic on the table entries that are curr

2条回答
  •  时光说笑
    2021-01-16 01:14

    Even if you have no other formulas on the worksheet, if you include a Subtotal() formula somewhere on the sheet referencing the table, the Subtotal() will recalculate every time the autofilter is changed.

    You can use this to trigger a Calculate() event macro.

    EDIT#1:

    Say we have an AutoFilter set on column A of a sheet named data. Sheet data also contains many other formulas. If we use the Calculate() event in the data worksheet, we will get fires any time any of these formulas re-calculate.

    We create a new worksheet called trigger. This new worksheet is comletely empty except for a single cell that contains:

    =SUBTOTAL(3,data!A1:A20)
    

    It is in the trigger worksheet that we place the Calculate() event macro.

    Now if we are using the data worksheet, we can make arbitrary changes and perform various recalculation and nothing fires, but if we change the AutoFilter, the event macro on trigger will see the change and fire!

提交回复
热议问题