sum cells with characters

mucah!t

Well-known Member
Joined
Jun 27, 2009
Messages
593
Hello all,

I'd like to sum all the numbers of cells proceeded by a "C"
In below example this would be cells M36 and N32 = 6
Any ideas?

Excel Workbook
LMN
32DFVC4
33TR2.5V
34VIUDF
354TRDF
36VC2DF
Sheet1
Excel 2003
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
May be this can give you an idea

Code:
Sub test()
Sum = 0
'Currenty this code works upto Cells(50,50). The range can be changed
For i = 1 To 50
    For j = 1 To 50
        If Cells(i, j).Value Like "C*" Then
            Sum = Sum + Right(Cells(i, j).Value, 1)
        End If
    Next
Next
MsgBox Sum
End Sub

Thanks,
Ogo
 
Upvote 0
Maybe

=SUM(IF(LEFT($L$32:$N$36,1)="C",--SUBSTITUTE($L$32:$N$36,"C","")))

Array confirmed with Shift Ctrl Enter.
 
Upvote 0
=SUM(IF(LEFT(L32:N36)="C",SUBSTITUTE(L32:N36,"C","")+0))
confirmed with ctrl+shift+enter
 
Upvote 0
Perhaps not as clean as Jason's suggestion, but based on using array formula's, try:
Code:
=SUM(IF(LEFT(L32:L36,1)="C",RIGHT(L32:L36,LEN(L32:L36)-1)+0,0))
Again, type the above in but press CTRL+SHIFT+ENTER (not just ENTER)
 
Upvote 0
Thanks guys,

JackDanice formula worked, the others give a value-error.
The only problem with JackDanice's formula is that when there's an "C" without a number in the range it gives an value-error.

Is there a solution for this?
Even better still would be if all occurances of a C [without a number] are counted as 8.
 
Upvote 0
All three suggestions work for me with your sample table.

Array entered again, try

=SUM(IF(LEFT($L$32:$N$36,1)="C",--SUBSTITUTE($L$32:$N$36,"C",IF(LEN($L$32:$N$36)=1,8,""))))

How does that compare?
 
Upvote 0

Forum statistics

Threads
1,224,503
Messages
6,179,135
Members
452,890
Latest member
Nikhil Ramesh

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
Back
Top