Sum only data contain X

Kishan

Well-known Member
Joined
Mar 15, 2011
Messages
1,648
Office Version
  1. 2010
Platform
  1. Windows
Using Excel 2000

Hi,

I need to sum only data's values are in column C with "X" only with X not the numbers.

Example data.


Book1
ABCDE
1
2
3
4DataSum Only
5DataWith X
6X|2|13
72|1|2
81|X|12
91|1|2
101|1|X2
112|1|X3
122|2|2
13X|1|23
14X|X|X
15X|X|22
161|1|1
171|X|23
182|X|13
192|X|24
202|2|2
212|1|X3
222|1|2
232|X|24
241|X|X1
25
Sheet1


Thank you in advance

Regards,
Kishan
 
Last edited:

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Give this formula a try...

=IF(ISNUMBER(SEARCH("X",C6)),IF(C6="X|X|X","",SUM(0+MID(SUBSTITUTE(C6,"X",0),{1,3,5},1))),"")
 
Last edited:
Upvote 0
Here is a VBA solution

Code:
Option Explicit


Sub SumX()
    Dim lr As Long
    Dim s As Long
    Dim i As Long, y As Long
    lr = Range("C" & Rows.Count).End(xlUp).Row
    s = 0
    For i = 6 To lr
        If InStr(Range("C" & i), "X") > 0 Then    'X is case sensitive here.  I used Caps
            y = Range("C" & i).Offset(0, 1)
            s = s + y
        End If
    Next i
    MsgBox ("Sum of s = " & s)


End Sub
 
Upvote 0
Hi Rick, could you please explain your formula?
This, from the first IF...

ISNUMBER(SEARCH("X",C6))

tests whether C6 contains an X or not. If not, the formula output the empty text string "". If it does contain an X, then this gets executed...

F(C6="X|X|X","",SUM(0+MID(SUBSTITUTE(C6,"X",0),{1,3,5},1)))

The first test C6="X|X|X" looks to see if there are only X's in the cell... if yes, the empty text string is returned (as per the OP's request), otherwise this is executed...

SUM(0+MID(SUBSTITUTE(C6,"X",0),{1,3,5},1))

The first thing this part does ie substitute a zero in place of any X's, then it creates an array of numbers pulled from the first, third and fifth characters in the text (those correspond to the numbers between the vertical bar symbol), then 0 is added to each array element so that the SUM function has real numbers to add (it cannot add an array of text constants even if those text items look like numbers, so the text must be converted to real numbers).
 
Upvote 0
Here is a VBA solution

Code:
Option Explicit


Sub SumX()
    Dim lr As Long
    Dim s As Long
    Dim i As Long, y As Long
    lr = Range("C" & Rows.Count).End(xlUp).Row
    s = 0
    For i = 6 To lr
        If InStr(Range("C" & i), "X") > 0 Then    'X is case sensitive here.  I used Caps
            y = Range("C" & i).Offset(0, 1)
            s = s + y
        End If
    Next i
    MsgBox ("Sum of s = " & s)


End Sub
Hi alansidman, VBA is giving a message total sum of the range not individual, as I require.

Thank you for looking in it.

Kind Regards,
Kishan
 
Upvote 0
Give this formula a try...

=IF(ISNUMBER(SEARCH("X",C6)),IF(C6="X|X|X","",SUM(0+MID(SUBSTITUTE(C6,"X",0),{1,3,5},1))),"")
Brilliant!! Rick, Thank you for your help and time.

Appreciate it. Working as treat.

Regards,
Kishan :)
 
Upvote 0

Forum statistics

Threads
1,224,800
Messages
6,181,045
Members
453,014
Latest member
Chris258

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