Run VBA code automatically after running a filter

后端 未结 3 1890
北荒
北荒 2021-01-14 11:27

I\'ve got a code written that categorizes employees along with their qualifications. In order to weed out employees with unwanted qualifications I have applied a filter to e

3条回答
  •  鱼传尺愫
    2021-01-14 12:02

    Still need to investigate but looks like Chart Calculate event is triggered when Calculation = xlCalculationManual. At least works on my Excel 2007. So the steps are:

    • create a chart (saying "Chart 1" on Sheet1) which actually uses data from any of your table column
    • check that it updates its picture when you change the filter
    • create a new class e.g. clsChartEvents:

      Public WithEvents Chart As Chart
      Private Sub Chart_Calculate()
        Stop
      End sub
      
    • add this code to some module or class:

      Private chartEvents as new ChartEvents 'create a module-scope variable
      sub SubscribeToChartEvents
        set chartEvents.Chart = Sheet1.ChartObjects("Chart 1").Chart
      end sub
      
    • execute SubscribeToChartEvents
    • change a filter and you should appear in Sub Chart_Calculate()

提交回复
热议问题