Solved

sum based on character value

Posted on 2011-02-20
7
253 Views
Last Modified: 2012-05-11
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.
0
Comment
Question by:sscastor115
  • 4
  • 3
7 Comments
 
LVL 50

Expert Comment

by:barry houdini
ID: 34938966
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
0
 

Author Comment

by:sscastor115
ID: 34939064
my apologies, my sheet is setup as attached. As C2 is a column in use I'm not sure how to adjust test.xls
0
 
LVL 50

Accepted Solution

by:
barry houdini earned 500 total points
ID: 34939138
OK, disregard my previous reply, I assumed you had 2P, 12X, 8V in a single cell....

for your sheet you could use this "array formula" in S2

=SUM(IF(RIGHT(C2:P2)="V",SUBSTITUTE(C2:P2,"V","")+0))

confirmed with CTRL+SHIFT+ENTER and copied down the column...and the same for cell V2 although you'd replace "V" with "X" for the latter.

Personal time seems to be different as you have the "P" in a separate cell, is that right?

see attached

regards, barry
26834846v2.xls
0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 

Author Comment

by:sscastor115
ID: 34939187
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.
0
 

Author Comment

by:sscastor115
ID: 34939190
and then when I replace the { it shows the formula text in the cell instead of the calcuation
0
 
LVL 50

Expert Comment

by:barry houdini
ID: 34939226
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
0
 

Author Comment

by:sscastor115
ID: 34943351
that worked perfectly, I had never worked with an array so the { } confused me at first. Thanks for all your help
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now