Pedro Bernardos
Pedro Bernardos

Reputation: 67

Excel, how to make a for loop?

I have this code here:

=C5
-(IF(G9="C",(IF(G10=0,$C2,$C2-G10)),))
-(IF(H9="C",(IF(H10=0,$C2,$C2-H10)),))
-(IF(I9="C",(IF(I10=0,$C2,$C2-I10)),))

etc...

It continuates from G9 to J9.

Is there a way to make it with less code? In java I would have used a for loop, but I don't know how to do it with Excel

Thanks!!

Upvotes: 0

Views: 26

Answers (1)

Scott Craner
Scott Craner

Reputation: 152605

Use SUMPRODUCT:

=C5-SUMRPODUCT((G9:J9="C")*($C2-G10:J10))

Upvotes: 1

Related Questions