Im not sure exactly what you mean. but ill have a go at answering your query anyway.
To get a single answer on a row you could use the function
=SUMPRODUCT((A2="40x28")*(B2="Y")*(C2="P")*(D2=1)* (E2))
to get totals for certain conditions you could use this
=SUMPRODUCT((A2:A23="40x28")*(B2:B23="Y")*(C2:C23= "P")*(D2

23=1)*(E2:E23))
replacing 23 by your last row
or you could even write your Do While loop in VBA
for future posts can you try to be more specific about what you are trying to do.
HTH
David