I have a spreadsheet I made to calculate flight times to do just that.
I'll send you a copy if you like.
The way I found was to do a test to see if the end time was numerically less than the start time eg start at 22:00, finish at 02:00.
If yes, then add '1' to the finish time & then subtract start from finish.
Excel stores time as a decimal fraction, days are a whole number. Adding '1' has the effect of adding one whole day to the finish time ie 24 hrs.