Handling merged cells is not easy, and AFAIK, none of Excel's functions specifically handles merged cells.
I think that the first cell in a merged range is used, but this means that you will not be able to sort rows when the cell used for the sort is merged with a cell above it.
As an approach, perhaps have a source sheet with no merged cells and for groups enter the data in the appropriate cell in the first row for that group and subsequent cells in the group are linked by a simple =
e.g., B4 contains =B3
This makes the source sheet filterable and sortable.
Then add a 'display' sheet that links to the source data and uses merged cells.
Writing custom sort and or filter macros in VBA code sounds like a fairly major task. Doable but complex.
If you have a source sheet with no merged cells which gets sorted etc. then a macro to create a display worksheet might work. The macro goes through the sorted source data and if a cell to be copied (source to display) is the same as the cell above, then instead of copying it, it merges the two cells on the display worksheet. You could also include formatting to the code, such as borders and horizontal centering.
I will be interested to hear if others have ideas for how this might be approached.