Adding variable number lengths from string

Nyanko

Active Member
Joined
Sep 1, 2005
Messages
437
I'm looking for a way to add the numerical values in a list of string items that have an identifier as it's right character (via formula not VBA), however the length of the numbers can vary !

The real world application for this formula involves adding up overtime shifts hours worked by individuals. We have lots of shift codes denoting number of hours worked and the overtime shifts are marked with a £ as the right character

For example
D8
D12
D12£
D1£

The total hours worked is 33 but I'd like a formula to return the value 13 for just the figures ending in a £

Would it be too much to mention that sometime we have half shifts ?

For example
D8
D12
D12£
D1.5£

So the required value for this would be 13.5

I've been trying to use sumproduct and the nearest I can get is :

Code:
=SUM(IF(RIGHT(G$34:G$402,1)="£",--LEFT(G$34:G$402,LEN(G$34:G$402)-1))) which #value! errors
or 
=SUMPRODUCT((RIGHT(G$34:G$402,1)="£")*(LEFT(G$34:G$402,1)<>"U")) which only counts the total occurrences of the cells containing a £

I think that the answer lies with sumproduct, but I'm having trouble finding the right comination :)
 

Some videos you may like

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.

craig.penny

Well-known Member
Joined
May 8, 2009
Messages
656
Put this formula in the cell and press Ctrl-Shift-Enter to enter it as an array formula. It won't work otherwise.

Code:
=SUM(1*IF(RIGHT($G$34:$G$402,1)="£",MID($G$34:$G$402,2,LEN($G$34:$G$402)-2),0))

After you enter it you should see curly (nyuck nyuck nyuck) brackets like "{" and "}" at the ends.
 

Nyanko

Active Member
Joined
Sep 1, 2005
Messages
437
Put this formula in the cell and press Ctrl-Shift-Enter to enter it as an array formula. It won't work otherwise.

Code:
=SUM(1*IF(RIGHT($G$34:$G$402,1)="£",MID($G$34:$G$402,2,LEN($G$34:$G$402)-2),0))

After you enter it you should see curly (nyuck nyuck nyuck) brackets like "{" and "}" at the ends.

That is utter genius. Thank you, it's now gonna take me the rest of the day to figure out how you did it :D
 

Watch MrExcel Video

Forum statistics

Threads
1,122,499
Messages
5,596,517
Members
414,074
Latest member
Matthew Kakde

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top