Excel function to test whether string contains ANY of $THESE CHARACTERS - excel

Given:
$Characters
Is there an excel function to test whether a Cell contains ANY of the Characters in $Characters?

There is an array formula method but it also involves the INDIRECT function to check the length of the string to be the $Characters string to be tested. OFFSET is a volatile formula that will recalculate whenever any value in the workbook changes.
        
The array formula in C2 is,
=AND(MAX(IFERROR(SEARCH(MID($E$2, ROW(INDIRECT("1:"&LEN($E$2))), 1), $A2), 0)))
Array formulas need to be finalized with Ctrl+Shift+Enter↵. Once entered correctly, they may be filled or copied to another location.
I've used the SEARCH function which is case-insensitive. If you require a case sensitive search, substitute SEARCH for the FIND function.

Here is an array formula that should do that.
When you confirm the formula, hold down ctrl+shift while hitting enter. If you do this correctly, Excel will place braces {...} around the formula which you can see in the formula bar.
Characters is either a range containing your list of characters (or substrings) to be tested, or an array constant.
=OR(IFERROR(SEARCH(Characters,A1),FALSE))

Related

Get element from array constant?

If you have a CSE array constant as follows in cell A1:
{={2,4,6,8}}
How can you get a specific element from the array constant? I tried the following formulas but they all return the first value of the array constant (2).
=INDEX(A1, 0)
=INDEX(A1, 1)
However, it does work if the array is not a reference. The following formula returns the 3rd element (6).
=INDEX({2,4,6,8},3)
Thank you
You could put the array constant in a Name instead of a cell.
Then INDEX will work with it properly with no implicit intersection.
Or you could parse the formula using the FORMULATEXT function, but that sounds tedious.
Try =INDEX(A1#,1). The # tells excel that A1 is a spill formula (more than 1 cell long). The array index starts at 1, not 0 in this case.
As a side note, Index knows you are referring to an index, not a row, when you give it a 1D array. In your example =INDEX(A1#,4) and =INDEX(A1#,1,4) return the Fourth item in your array (8 in this case), but =INDEX(A1#,4,1) will give you the error #REF!. If you define your array vertically {={2;4;6;8}}, =INDEX(A1#,4) and =INDEX(A1#,4,1) both work.
Edit: It looks like this does not always work in Excel 365 when a an array formula is created using Ctrl+Shift+Enter. I think this is due to the changes in 365. Array formulas have pretty much been replaced with spill formulas. Entering ={2,4,6,8} is mostly equivalent to a pre-365 array formula, but creating an array formula with Ctrl+Shift+Enter confines the output to as many cells as selected. In Dan's case, he selected only one cell and the formula doesn't automatically spill, so the formula is confined only to that cell. Excel seems to treat that cell as if it only contains that array element. If you select 2 cells and enter an array formula then =INDEX(A1#,2) will work but =INDEX(A1#,3) returns #REF!.
Edit2: It is possible with the FORMULATEXT Function as #DickKusleika suggested. Here is a function adapted from ExcelJet that does the job.
=LET(
DesiredIndex, 1,
ArrayFormulaRef, A1,
Formula, FORMULATEXT(ArrayFormulaRef),
FormulaLen, LEN(Formula),
CSVStart, FIND("{",Formula,2),
CSV, MID(LEFT(Formula,FormulaLen-1),CSVStart+1,FormulaLen),
TRIM(MID(SUBSTITUTE(CSV,",",REPT(" ",LEN(CSV))),(DesiredIndex-1)*LEN(CSV)+1,LEN(CSV)))
)

=ISNUMBER(SEARCH()) formula not working properly

Basically, im trying to search if values from column b is contained in cells on column a
I am currently using the formula
=ISNUMBER(SEARCH(B1,$A:$A))
and using it inside a conditional formatting to highlight the cells in column A that contains strings from column B. But it is not highlighting the correct cells
any advice?
Problem is that your ISNUMBER(SEARCH(…. formula is returning an array of values {FALSE;TRUE;FALSE;FALSE;...} one return for each item in within_text. You need to know if any of those items match.
So, with your formula, consider the array formula modification
=OR(ISNUMBER(SEARCH(B1,$A:$A)))
Since this is an array formula, you need to "confirm" it by holding down ctrl + shift while hitting enter. If you do this correctly, Excel will place braces {...} around the formula as observed in the formula bar
If you don't like to use the CSE entry method, you could use this formula which will return zero for no matches, or be non-zero for any matches:
=SUMPRODUCT(-ISNUMBER(SEARCH(B1,$A:$A)))
Excel's SEARCH function is used to find the position of one string within another string. Generally you use it like this:
=SEARCH("String A", "A Longer String Containing String A")
This will return the character index where first string starts within the second string, which in this case would be 28.
What you really need is a VLOOKUP. Since you're doing a textual search (substring), you need your range to be of text type instead of number.
You should do the following:
Add an extra column to the right of Column A and use TEXT function to convert entries to textual form:
=TEXT(A1, "#")
Now you can use VLOOKUP to perform a substring-match in this textual range. VLOOKUP supports wildcards when you do not ask it to perform an exact match (4th argument should be FALSE). Here is your formula then:
=VLOOKUP("*" & C1 & "*",$B:$B,1,FALSE)
Note that I have passed column B (textual column) as the lookup range, whereas C1 is the cell containing the text that you want to search.
This method also has the additional advantage that it returns the actual matched entry from the range so you don't have to find it manually.
Once you have your results, you can apply conditional formatting to it.
Highlight column A (or the relevant range in column A starting cell A1) with the first cell (which is A1 in this case) as the active cell, use the following formula as the conditional formatting rule:
=(SEARCH($B1,$A1)*(LEN($B1)>0))>0
The logic is to first search the given sub-string from the main string, then multiple the result by LEN($B1)>0 to exclude the result of 1 returned for blank cells in column B.
Note: Conditional Formatting works in array fashion so even though the formula only looks at values in the first row of the range, as long as you use the relative (or in some cases absolute) cell references correctly and highlight the result range correctly before setting up the rule, the rule will be applied across in the same way as for the first row of the array as demonstrated in this example.

empty string value if there is no date inside range

I have following formula which i add as a picture here in the question as well.
=MIN(INDIRECT(ADDRESS(ROW(AF4);COLUMN(AF4))&":af"& (MIN(IF(A4:A108="";ROW(A4:A108))))))
AF3 and AG3 columns should calculate the minimum date in dynamic range(based on empty cell in A). As you can see in AF, if all values are "N/A" formula brings automatically 00.01.1900 by default. I want it to return empty string if the range does not contain any date. If it has a date inside the range, the formula should work as it works in AG3.
How can i do this?
Wrap the formula in IF like below and test:
=IF(MIN(AF4:INDEX(AF:AF,MIN(IF(A4:A108="",ROW(A4:A108)))))=0,"",MIN(AF4:INDEX(AF:AF,MIN(IF(A4:A108="",ROW(A4:A108))))))
I have dropped INDIRECT which is volatile. Above construct is less volatile.
It is ARRAY formula so you need to CTRL+SHIFT+ENTER.
Make sure you replace "," with ";" in formula arguments at your end.
You could follow #shrivallabha redij's suggestion of a custom format or use a TEXT statement like this
=TEXT(MIN(INDIRECT(ADDRESS(ROW(AF4),COLUMN(AF4))&":af"& (MIN(IF(A4:A108="",ROW(A4:A108)))))),"dd.mm.yyyy;;")
EDIT
I agree with #shrivallabha's advice to use Index instead of Indirect. If I was doing this from scratch, I would also use Aggregate:
=IFERROR(AGGREGATE(15,6,AF4:INDEX(AF4:AF108,AGGREGATE(15,6,ROW(A4:A108)/(A4:A108=""),1)),1),"")

Use result of IF formula in single cell Excel array formula

I have a column J with the below array formula:
=IF(ISNUMBER($H$5:$H$263), $H$5:$H$263, $I$5:$I$263)
And a cell on a summary line that references the contents of that column:
=SUMIF($J$5:$J$267,"<"&(TODAY()+365), $L$5:$L$263)
The above gives me the result I want, but I am wanting to consolidate this down into a single formula.
I have tried the below:
=SUMIF(IF(ISNUMBER($H$5:$H$263), $H$5:$H$263, $I$5:$I$263),"<"&(TODAY()+365), $L$5:$L$263)
But it ends up only summing the contents of the left side of the IF
So the below can get me what I want:
=SUMIF(IF(ISNUMBER($H$5:$H$263), $I$5:$I$263, $H$5:$H$263),"<"&(TODAY()+365), $L$5:$L$263) + SUMIF(IF(ISNUMBER($H$5:$H$263), $H$5:$H$263, $I$5:$I$263),"<"&(TODAY()+365), $L$5:$L$263)
But I'm not sure what I am doing wrong with the first shorter formula.
Use this array formula:
=SUM(IF(IF(ISNUMBER($H$5:$H$263),$H$5:$H$263,$I$5:$I$263)<TODAY()+365,$L$5:$L$263))
Being an array formula it needs to be confirmed with Ctrl-Shift-Enter instead of Enter when exiting edit mode. If done correctly then Excel will put {} around the formula.
You can use SUMPRODUCT without the need for CSE:
=SUMPRODUCT(((ISNUMBER($H$5:$H$263)*($H$5:$H$263)+(NOT(ISNUMBER($H$5:$H$263)) * ($I$5:$I$263)))<TODAY()+365)*$L$5:$L$263)
I would also recommend the use of EDATE(TODAY(),12) in place of TODAY()+365 to deal with leap year.

Excel - Checking if cells in range match and then replace cell

I need to check if cell A5(Song Name), B5(Album), C5(Artist) is the same text as any text in Worksheet 2 from A5:A104, B5:B104, C5:C105, respectively.
And if it does, I want the cell I am writing this formula in to change to the same value at E5:E104 from Worksheet 2.
This is what I made, which does not work:
=IF(AND(A5='Worksheet 2'!A5:A104,B5='Worksheet 2'!B5:B104,C5='Worksheet 2'!C5:C104),'Worksheet 2'!E5,"")
What am I doing wrong?
You need to use an array formula to do this. What you were trying to do was nearly right, but it won't work as you expect unless you enter it as an array formula by pressing Ctrl+Shift+Enter. Try this, entered as an array formula:
=IFERROR(INDEX('Worksheet 2'!$E$1:$E$104,MIN(IF(A5='Worksheet 2'!$A$5:$A$104,IF(B5='Worksheet 2'!$B$5:$B$104,IF(C5='Worksheet 2'!$C$5:$C$104,ROW('Worksheet 2'!$E$5:$E$104),2000000),2000000),2000000))),"No match found.")
The logic gets complicated by the fact that you have to use a function that can return a single value from an array (MIN() in this formula).
=IF(ISERROR(MATCH(A5&B5&C5,'Worksheet 2'!A5:A104&'Worksheet 2'!B5:B104&'Worksheet 2'!C5:C104,0)),"",'Worksheet 2'!E5)
Enter as an array function with Ctrl+Shift+Enter

Resources