Reputation: 11
I have a spreadsheet with a couple of cells with the following input:
V4 V5 V2 V3 V5 V7
I am trying to tell Excel to check the value infront, and see if its a V. If this is TRUE, count the value next to it. This has to be done in a loop until it has passed through the range and summed all of the values.
This formula gets me nearly there.. but still no workable output.
=SUMPRODUCT(--(LEFT(A1:AO1,1)="V")*SUM(RIGHT(A1:AO1,1)))
VBA is not a option.
Upvotes: 0
Views: 1429
Reputation: 96753
You were very close, use the array formula:
=SUMPRODUCT(--(LEFT(A1:AO1,1)="V"),IFERROR(--RIGHT(A1:AO1,1),0))
Array formulas must be entered with Ctrl + Shift + Enter rather than just the Enter key.
EDIT#1:
As mentioned in the Comment by guitarthrower , this will work if there is more than one digit following the V:
=SUMPRODUCT(--(LEFT(A1:AO1,1)="V"),IFERROR(--RIGHT(A1:AO1,LEN(A1:AO1)-1),0))
EDIT#2:
If you are using a version of Excel before 2007, then use this array formula:
=SUMPRODUCT(--(LEFT(A1:AO1,1)="V"),IF(ISERROR(--RIGHT(A1:AO1,LEN(A1:AO1)-1)),0,--RIGHT(A1:AO1,LEN(A1:AO1)-1)))
Upvotes: 1
Reputation: 3655
The other answers all require a helper column, but your questions seems to suggest that is what you are trying to avoid. try the formula below (abjust range as necessary):
=SUMPRODUCT(--(LEFT(A1:A8,1)="V"),VALUE(RIGHT(A1:A8,1)))
Please bear in mind that this will ONLY work if the number after the letter is always a single digit
Upvotes: 0
Reputation: 38
Don't fight excel, the obvious solution is to do:
=IF(LEFT(A1,1) = "v", RIGHT(A1,1), 0)
on a column (you can hide it) and then sum it normally.
Upvotes: 0
Reputation: 879
Assuming the value next to the V
is one digit long, you can use the following IF
statement in excel to check if there is indeed a V
, then assign the cell the value next to the V
, or a zero.
=IF(LEFT(A1; 1)="V"; RIGHT(A1;1);0)
Afterwards, it's up to you to tweak it a bit.
Upvotes: 0