EXCEL form accounting for the daily use of peak and valley tariffs electricity time

Your data structure and basis need to be adjusted, as follows:

Input the formula in cell D4:

=MAX(0,IF($B4>D$1,0,IF($C4<D$1,$C4,D$1)-IF($B4>C$1,$B4,C$1))*24)

Copy and pull down and pull right to J6 cells, yellow bottom data will be automatically accounted for with your E, C column time data, K columns are totaled with SUM can be.

Which, C1: J1 must be entered into the standardized data.