As you have discovered, Merged Cells are very bad! They do not play nicely with VBA and other functions, such as sorting. Most serious Excel programmers will strongly advise you not to use them.
Note that if you are just merging cells across multiple columns in a row, you can easily obtain the safe visual effect without all the problems that merged cells cause by using the "Center Across Selection" formatting option. If you make this change, you should be able to get your VBA and formulas to work without issue.