Determine if character appears in SUM function

ChristineJ

Well-known Member
Joined
May 18, 2009
Messages
761
Office Version
  1. 365
Platform
  1. Windows
In cell A5, I'd like to return "Yes" if the text within any SUM function in E8 contains a "+" sign.

Should return "Yes" in A5 if E8: =SUM(D2+E2+F2)+SUM(K6:K19)+SUM(X4+Y4+Z4)
Should return "Yes" in A5 if E8: =SUM(D2:F2)+SUM(K6:K19)+SUM(X4+Y4+Z4)
Should return "Yes" in A5 if E8: =SUM(D2+E2+F2)
Should not
return "Yes" in A5 if E8: =SUM(D2:F2)+SUM(K6:K19)+SUM(X4:Z4)
Should not return "Yes" in A5 if E8: =SUM(D2:F2)

The "+" signs between the SUM functions are not relevant to returning a "Yes".

Can this be done with either VBA or a formula? Thanks!
 
Right, I didn't account for that scenario since we look for element starting with 'SUM(`, and not '=SUM('. So try:

Excel Formula:
=NOT(ISERROR(FILTERXML("<t><s>"&SUBSTITUTE(FORMULATEXT(A1),")+","</s><s>)")&"</s></t>","//s[starts-with(translate(.,'=*^-/',''), 'SUM(') and contains (.,'+')][1]")))

But note that the regex option provided by RoryA would still be more secure.
 
Upvote 0

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Right, I didn't account for that scenario since we look for element starting with 'SUM(`, and not '=SUM('. So try:

Excel Formula:
=NOT(ISERROR(FILTERXML("<t><s>"&SUBSTITUTE(FORMULATEXT(A1),")+","</s><s>)")&"</s></t>","//s[starts-with(translate(.,'=*^-/',''), 'SUM(') and contains (.,'+')][1]")))

But note that the regex option provided by RoryA would still be more secure.
Many thanks for the follow up!
 
Upvote 0
FWIW, two comments
- since SUM would always be in upper case in the formula I don't think the UDF needs the 'ignorecase' line
- since we only need to find a single case of a SUM with a "+" for the result to be TRUE/YES I don't think the UDF needs the 'Global' line
 
Upvote 0
FWIW, two comments

- since SUM would always be in upper case in the formula I don't think the UDF needs the 'ignorecase' line
- since we only need to find a single case of a SUM with a "+" for the result to be TRUE/YES I don't think the UDF needs the 'Global' line

I also do not know what sort of formula might turn up but the UDF could fail (ie return FALSE) with a formula like
Excel Formula:
=SUM((D2)+(E2))

or perhaps a more 'legitimate' one like this (unless you do not want to flag this one?)
Excel Formula:
=SUM((E2-F2)/2,(X4+Y4+Z4)*2)

Do we need to try to think of ways to cope with that sort of thing or are you only expecting fairly standard/basic formulas?
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,932
Messages
6,122,334
Members
449,077
Latest member
Jocksteriom

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