SUBTOTAL requires that the data being subtotalled, be kept together. You would have to use some other function like SUMPRODUCT, SUMIF or SUMIFS that don't require that the rows be kept together. If you have several subtotal ranges and you sort, then the ranges get messed up because they are no longer together. I suspect that your subtotal is really a TOTAL but I don't know for sure as your example doesn't show what exactly you are doing.
A SUBTOTAL formula with several ranges would look like this:
Bookmarks