I would like to use Bob's array formula as below,
If(x1="PGR",SUM(N(OFFSET(INDEX(Sheet1!$C$12:$H$16,0,MATCH(MIN($B2,3)&$C2,{"1E","2E","3ÂE","1O","2O","3O"},0)),MATCH(MID($D2,ROW(INDIRECT("1:"&LEN($D2))),1),Sheet1Â!$B$12:$B$16,0)-1,0))),"")
The first condition returning the array formula.