VBA:Trigger macro on column filter

calendar_today Asked Apr 9, 2013
thumb_up 9 upvotes
history Updated April 14, 2026

Direct Answer

I was just thinking if I can post this answer. I guess some of you will not like it as it is not direct answer by presentation of bypass solution. However I think I can show that…. This is a 11-line Excel VBA snippet, ranked #283rd of 303 by community upvote score, from 2013.


The Problem (Q-score 2, ranked #283rd of 303 in the Excel VBA archive)

The scenario as originally posted in 2013

Is there a way we can trigger a macro function on column filter in excel??

Please help

Thanks.

Why community consensus is tight on this one

Across 303 Excel VBA entries in the archive, the accepted answer here holds niche answer (below median) status — meaning voters are unusually aligned on the right fix.


The Verified Solution — niche answer (below median) (+9)

11-line Excel VBA pattern (copy-ready)

I was just thinking if I can post this answer. I guess some of you will not like it as it is not direct answer by presentation of bypass solution. However I think I can show that idea as we don’t have all project assumptions in the question.

Let’s agree- we all know that there is no event which fires after we change filtering. However, I see one option.

Changing filter could fire Worksheet_Calculate event (not Worksheet_Change). If there is any single formula within your sheet than we will fire that event each time we change filtering criteria using our mouse.

Step 1. put any single formula in the sheet, like in cell ZZ1 where =ZZ2

Step 2. I assume that our data range starts in Range(A1) and we have titles in first row (see the picture). I assume also there is nothing below that area.

enter image description here

Step 3. Put that following solution in Sheet1 module.

Private Sub Worksheet_Calculate()

If ActiveSheet.Name = "Sheet1" Then
    If Cells(Rows.Count, 1).End(xlUp).Row = 1 Then
        MsgBox "No data available"
    Else
        MsgBox "There are filtering results"
    End If
End If
End Sub

Step 4. Using filter would fire that event and result with following situations:

enter image description hereenter image description here

I hope someone will like it and can use that. Even if it’s only a bypass idea.

Error-handling details to lift with the snippet

This answer wires error flow through MsgBox / Err.Description. Keep that intact: stripping it to “make it cleaner” removes the signal you’ll need when the macro fails silently on a user machine.


When to Use It — classic (2013–2016)

Ranked #283rd in its category — specialized fit

This pattern sits in the 97% tail relative to the top answer. Reach for it when your scenario closely matches the question title; otherwise browse the Excel VBA archive for a higher-consensus alternative.

What changed between 2013 and 2026

The answer is 13 years old. The Excel VBA object model has been stable across Office 2013, 2016, 2019, 2021, 365, and 2024/2026 LTSC, so the pattern still compiles. Changes that might affect you: 64-bit API declarations (use PtrSafe), blocked macros in downloaded files (Mark-of-the-Web), and the shift toward Office Scripts for web-first workflows.

help
Frequently Asked Questions

This is a below-median answer — when does it still fit?
expand_more

Answer score +9 vs the Excel VBA archive median ~4; this entry is niche. The score plus 2 supporting upvotes on the question itself (+2) means the asker and 8 subsequent voters all validated the approach.

Does the 11-line snippet run as-is in Office 2026?
expand_more

Yes. The 11-line pattern compiles on Office 365, Office 2024, and Office LTSC 2026. Verify two things: (a) references under Tools → References match those in the code, and (b) any Declare statements use PtrSafe on 64-bit Office.

Published around 2013 — what’s changed since?
expand_more

Published 2013, which is 13 year(s) before today’s Office 2026 build. The Excel VBA object model has had no breaking changes in that window. Three things to re-test: (1) blocked macros on downloaded files (Mark-of-the-Web), (2) 64-bit API declarations (PtrSafe, LongPtr), (3) any shift toward Office Scripts for web scenarios.

Which Excel VBA pattern ranks just above this one at #282?
expand_more

The pattern one rank above is “How to change format of a column of excel sheet in c#?”. If your use case overlaps, compare both before committing.

Data source: Community-verified Q&A snapshot. Q-score 2, Answer-score 9, original post 2013, ranked #283rd of 303 in the Excel VBA archive. Last regenerated April 14, 2026.