Is there a way, to trigger an event (call a sub) in Excel VBA, when i manually hide a row/column?
I want the same row to be hidden in all following sheets, when it i
There is no direct event trigger to capture hiding or unhiding columns. There are clumsy workarounds, using formulae in cells but those feel like a kludge when using and not really flexible.
However, there is an indirect way to capture this event if you use Excel 2007 or newer. This is neat and extremely flexible.
customUI14.xml
(for Excel 2010) or customUI.xml
(for Excel 2007).Reference: This excellent solution was provided by Andy Pope here (MSDN link).
Custom XML code:
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" >
<commands >
<command
idMso="ColumnsHide"
onAction="Column_Hide_Macro"/>
<command
idMso="ColumnsUnhide"
onAction="Column_UnHide_Macro"/>
</commands >
</customUI>
Custom UI Editor screenshot:
VBA code:
Sub Column_Hide_Macro(control As IRibbonControl, ByRef CancelDefault)
MsgBox ("You have hidden a column")
' You may put your code here
' to check if your monitored row is hidden
CancelDefault = False ' This enables the default action to continue
End Sub
Sub Column_UnHide_Macro(control As IRibbonControl, ByRef CancelDefault)
MsgBox ("You have unhidden a column")
' You may put your code here
' to check if your monitored row is unhidden
CancelDefault = False ' This enables the default action to continue
End Sub