>> I commented it out as I then used the formula
That is the problem then.
The function returns a STRING, which is some textual data. But from what you are saying, you actually want a function that returns a DATE or DOUBLE to be used in calculations.
As it stands, the function would be useful for somewhat formatting and displaying time data.
Here's just a quick test with time:
Enter into these cells on a new sheet:
A1: 12:23
B1: 13:23
C1: =A1-B1
D1: 13:44
E1: =D1+C1
You will notice that even if you made column C really wide, Excel cannot display -1hr. BUT, change the formatting to General and you will see that the DOUBLE value representing -0.04167 of a day is stored there. It also correctly calculates E1.
Hopefully that helps some in your understanding.
For your formula, try this:
=IF(C2>=$M$1,C2-$M$1,IF(C2=TIME(0,1,0),1-(Time(0,0,0)-$M$1),1-(C2-$M$1)))
It may be possible to further simplify, but I took out the function and changed "24:00" to the numeric value 1.