Using Excel VBA Events to detect merging/unmerging of cells?

后端 未结 2 1713
遇见更好的自我
遇见更好的自我 2021-01-27 04:47

I am trying to find a way to detect the immediate use of merging (or unmerging) cells. The change event triggers nor does the selectionchange. I\'ve tried some of the other, but

2条回答
  •  南方客
    南方客 (楼主)
    2021-01-27 05:30

    As far as I know, there is no way to detect formatting changes on a cell. Merging is considered a format change and is therefore undetectable via VBA events. However, I did some digging, and found this interesting list:

    • Changing the formatting of a cell doesn't trigger the Change event (as expected). But copying and pasting formatting does trigger the Change event. Choosing the Home=>Editing=>Clear=>Clear Formats command also triggers the event.
    • Merging cells doesn't trigger the Change event, even if the contents of some of the merged cells are deleted in the process.
    • Adding, editing or deleting a cell comment doesn't trigger the Change event.
    • Pressing Delete generates an event even if the cell is empty to start with.
    • Cells that are changed by using Excel commands may or may not trigger the Change event. For example, sorting a range or using Goal Seeker to change a cell does not trigger the event. But using the spell checker does.
    • If your VBA procedure changes the contents of a cell, it does trigger the Change event.

    From Excel 2013 Power Programming with VBA by John Walkenbach Source

    So basically, if someone is just merging or unmerging cells, there is no way to detect that through a VBA event.

提交回复
热议问题