I need help to compose a formula in excel. Basically picture below explain what i need, this is just a sample. In column E is many different entry. From time to time I need to SUM in column G from some cells column E, depending of position of No."1" in column B. No."1" is always a mark when I need to SUM, and the distance of No. "1" can varied.

Or it can be as per next picture. In Column A is "date and Time" at 12:00 need SUM from cells in column E to previous 12:00 in column A. Hope that is clear what I need.