Dismissing special characters in a text string

Newbienew

Active Member
Joined
Mar 17, 2017
Messages
395
Office Version
  1. 2016
Platform
  1. Windows
So my dilemma is, I have 1 cell with a text string that contains special characters, such as, & or +. My current formula is tied in with a hlookup and use the left and right formula to achieve my goal. But there are other variations that this does not work on. I would like for the Hlookup formula I have to return the added results with out the special characters and whatever is in the cell. I hope below displays the issues I am facing.

Awards Stats.xlsx
ABCD
25opmkjkju
261215452
27
28
29op+mk27
30&mk#N/A
31mk+jk&ju62
32
Sheet1
Cell Formulas
RangeFormula
B29B29=HLOOKUP(LEFT(A29,2),A25:D26,2,FALSE)+HLOOKUP(RIGHT(A29,2),A25:D26,2,FALSE)
B30B30=HLOOKUP(LEFT(A30,2),A25:D26,2,FALSE)+HLOOKUP(RIGHT(A30,2),A25:D26,2,FALSE)
B31B31=HLOOKUP(LEFT(A31,2),A25:D26,2,FALSE)+HLOOKUP(MID(A31,4,2),A25:D26,2,FALSE)+HLOOKUP(RIGHT(A31,2),A25:D26,2,FALSE)
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
This will work for the example provided (SEARCH assumes you don't need case sensitive?) but will quickly break down if the data isn't this simple, e.g. as shown in red.

ABCD
25opmkjkju
261215452
27
28
29op+mk27
30&mk15
31mk+jk&ju62
32qop+jkju59
Sheet1
Cell Formulas
RangeFormula
B29:B32B29=SUMPRODUCT(ISNUMBER(SEARCH(A$25:D$25,A29))*A$26:D$26)

If your data is more complicated, perhaps you could post some more examples, and let us know whether the only special characters will be & or +
 
Upvote 0
Could be

varios 23nov2023.xlsm
ABCD
25opmkjkju
261215452
27
28
29op+mk27
30&mk15
31mk+jk&ju17
Hoja3
Cell Formulas
RangeFormula
B29:B31B29=HLOOKUP(LEFT(SUBSTITUTE(SUBSTITUTE(A29,"&",""),"+",""),2),$A$25:$D$26,2,0)+IF(LEN(A29)>3,HLOOKUP(RIGHT(A29,2),$A$25:$D$26,2,0))


(edit)
 
Upvote 0
Taking @StephenCrump's idea just a little further, you could try this.
If there are more special characters, then more SUBSTITUTE's would be required.
This would still not return the correct result if the row 25 values could occur multiple times - see row 33 where if this data is possible I assume that the result should be 75 not 60

BTW, can you please confirm whether you are still using Excel 2016?

23 11 24.xlsm
ABCD
25opmkjkju
261215452
27
28
29op+mk27
30&mk15
31mk+jk&ju62
32qop+jkju0
33mk&jk&mk60
Lookup Parts
Cell Formulas
RangeFormula
B29:B33B29=SUMPRODUCT(--ISNUMBER(SEARCH("+"&A$25:D$25&"+","+"&SUBSTITUTE(A29,"&","+")&"+")),A$26:D$26)
 
Upvote 0
Might the data have other operator like, +-*/ ? (add, subtract, multiply, divide)

for example:
=op*mk

In that case I suggest an UDF (with VBA code)
 
Upvote 0
Maybe like this:

Book1
ABCD
25opmkjkju
261215452
27
28
29op+mk27
30&mk15
31mk+jk&ju62
32mk&jk&mk75
Sheet1
Cell Formulas
RangeFormula
B29:B32B29=SUMPRODUCT($A$26:$D$26,(LEN(A29)-LEN(SUBSTITUTE(A29,$A$25:$D$25,"")))/LEN($A$25:$D$25))
 
Upvote 0
Maybe like this:

Book1
ABCD
25opmkjkju
261215452
27
28
29op+mk27
30&mk15
31mk+jk&ju62
32mk&jk&mk75
Sheet1
Cell Formulas
RangeFormula
B29:B32B29=SUMPRODUCT($A$26:$D$26,(LEN(A29)-LEN(SUBSTITUTE(A29,$A$25:$D$25,"")))/LEN($A$25:$D$25))
I would like to use your particular formula as a condition format, but having an issue applying it to an array. When I do it in a sample size, all of them turn red per not meeting the condition versus just the one. Then, when I use a larger array it seems not to work. This depends on where the $ is from what I can tell.

this is the CF formula =IF(SUMPRODUCT(HOME!$A3:$L3,(LEN($L5+$A$3:$X$149)-LEN(SUBSTITUTE($L5,HOME!$A2:$L2,"")))/LEN(HOME!$A2:$L2))<M5,"TRUE","")
The array is =$L$5:$M$150
The color is Red.

I am trying to apply a general CF verse row specific.
What can I do to make this work
 
Upvote 0
Not regarding the CF question, perhaps:

=SUMPRODUCT(IFERROR(HLOOKUP(MID(A29,ROW(INDIRECT("1:"&LEN(A29)-1)),2),$A$25:$D$26,2,0),0))

Book1
ABCD
25opmkjkju
261215452
27
28
29op+mk27
30&mk15
31mk+mk30
32ju&mk17
Sheet1
Cell Formulas
RangeFormula
B29:B32B29=SUMPRODUCT(IFERROR(HLOOKUP(MID(A29,ROW(INDIRECT("1:"&LEN(A29)-1)),2),$A$25:$D$26,2,0),0))
 
Upvote 0

Forum statistics

Threads
1,223,718
Messages
6,174,082
Members
452,542
Latest member
Bricklin

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