Link to home
Start Free TrialLog in
Avatar of sscastor115
sscastor115

asked on

sum based on character value

I would like to add up the values of cells based on a character that represents where the value is from.  for instance:
cells  might contain
2P, 12X, 8V
where is would indicate 2 hours personal time(P), 12 hours training (X) or 8 hours vacation(V)

in the cells that contain the totals I would like excel to count the hours based on the letter. So the training column would only count cells in the row where the number is followed by X. I have no idea how to use VBA so I'm looking for a formula to do this if possible.
Avatar of barry houdini
barry houdini
Flag of United Kingdom of Great Britain and Northern Ireland image

Hello sscastor115,

If you have data in A2:A10 try this formula

=SUMPRODUCT(MID(0&A$2:A$10&"00",FIND(C2,0&A$2:A$10&"00"&C2)-2,2)+0)

where C2 contains the letter to count, e.g. X

Assumes that you won't have numbers in cell greater than 99

see attached

regards, barry

26834846.xls
Avatar of sscastor115
sscastor115

ASKER

my apologies, my sheet is setup as attached. As C2 is a column in use I'm not sure how to adjust test.xls
ASKER CERTIFIED SOLUTION
Avatar of barry houdini
barry houdini
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
We had originally thought to make a cell that identified the specific time, but the use of split time in a day, regular hrs and vacation, did away with that thought. So it's just an old example. curiously in attempting to copy the formula to other cells, when i enter the cell the {} disappears and then the formula becomes invalid.
and then when I replace the { it shows the formula text in the cell instead of the calcuation
The formula is an "array formula" and needs to be entered in a specific way so that the curly braces appear automatically, you can't enter them yourself. If you put the formula in S2 then you should press the F2 key to select the formula - then you hold down the CTRL and SHIFT keys and at the same time press ENTER.....now the { and } should appear around the formula....and you can copy the formula down the column.

If you change the formula again you need to use CTRL+SHIFT+ENTER again

regards, barry
that worked perfectly, I had never worked with an array so the { } confused me at first. Thanks for all your help