Delete row if column contains value from to-remove-list with wildcard - excel

How do I make a wildcard so that I can find something that's not an exact match? I've tried taking out the 1, and also adding &"*" after A1 (the lookup value).
In other words, if I had app in the blacklist, how do I make it match apple so that it returns "Delete"?
Given sheet 2:
ColumnA
-------
apple
orange
You can flag the rows in sheet 1 where a value exists in sheet 2:
ColumnA ColumnB
------- --------------
pear =IF(ISERROR(VLOOKUP(A1,Sheet2!A:A,1,FALSE)),"Keep","Delete")
apple =IF(ISERROR(VLOOKUP(A2,Sheet2!A:A,1,FALSE)),"Keep","Delete")
cherry =IF(ISERROR(VLOOKUP(A3,Sheet2!A:A,1,FALSE)),"Keep","Delete")
orange =IF(ISERROR(VLOOKUP(A4,Sheet2!A:A,1,FALSE)),"Keep","Delete")
plum =IF(ISERROR(VLOOKUP(A5,Sheet2!A:A,1,FALSE)),"Keep","Delete")
The resulting data looks like this:
ColumnA ColumnB
------- --------------
pear Keep
apple Delete
cherry Keep
orange Delete
plum Keep

Use SEARCH Function but you will need to enter it as Array Formula.
Something like:
=IF(SUM(IFERROR(SEARCH(Sheet2!A$1:A$2,Sheet1!A1),0))>0,"Delete","Keep")
Enter using Ctrl+Shift+Enter.
This will check app or apple and all that's listed on Sheet2.
SEARCH Function also accepts wildcards (eg. ?- for single character, * - for 0 or more)
Important: I didn't use the overkill search range Sheet2!A:A since it will eat up significant calculation time.

To expand on L42's answer:
If the number of entries in Sheet1!A and Sheet2!A are unknown, the following formula will work with a maximum number of entries in Sheet2!A limited to 256.
=IF(A1<>"",IF(SUM(IFERROR(SEARCH(Sheet2!A$1:A$256,Sheet1!A1),0))+COUNTA(Sheet2!A$1:A$256)-256>0,"Delete","Keep"),"")
Change the value 256 in all three instances above to suit your needs.

Related

Return first row number in range where string matches any part of cell contents

Say I have three cells (one in each row):
A1
Apple Pear Lime Grape
Tom Bob Cliff Steve
Pi Rho Sigma Theta
There is a string of text in each single cell. Is there a formula I can write that will return the first row in which a given value appears?
For example, say I had cells like this:
Pear 1
Cliff 2
Steve 2
Pi 3
I would like to return the row where that value is a match for the original array of strings. I have experimented with SEARCH, FIND, and others, but these are good for comparing one row to another single row. I'm looking for something that will examine a whole array of rows and return the first reference row.
use MATCH with wildcards:
=MATCH("*"&C1&"*",A:A,0)

Excel SumProduct with if Statement in a cell.

I have a basic problem in Excel. I have a row with names and one with numbers. I try to find what is the sum of these numbers for a special name.
ex.
A B
Apple 12
Apple 12
Kiwi 9
Apple 4
Banana 51
Kiwi 12
Banana 4
Kiwi
So far I just use a basic sumproduct which works well. Like
=Sumproduct((A1:A8=A1)*(B1:B8)
This formula gives me back my total number of Apples
(12+12+4).
The problem is, if a cell contain some formula, then I have #VALUE! result.
Let say the last cell called Kiwi contain a code like
=if(A64="", "", 12)
Then it makes Kiwi empty if A64 is empty. Great.
But sumproduct don't work anymore.
I can't sort the name... any ideas?
Thank you
You can simply use =SUMIF() formula to get sum of these numbers for a special name.
=SUMIF($A$1:$B$64,A1,$B$1:$B$64)
or
=SUMIF($A$1:$B$64,"kiwi",$B$1:$B$64)
You can change these ranges based on your list. (You can even define dynamic name in Name Manager and then you can use that Name as your range.)
It's not the fact that your cell is calculated (contains a formula), it's because the result of the formula is a text.
Maybe you could use à 0 instead of the 0-length text and apply conditional formatting to your cells (font colour white if 0 value)
=if(A64="", 0, 12)

How can I check against a cell and it's opposite cell?

I'm trying to check if my cells contain a specific text, and if so, if the cell opposite my 'specific text' contains another specific text.
A| B
1, Banana
2, Orange
3, Banana
1, Banana
I want to count the number of occurrences a specific text has the word banana in the cell opposite.
My thought process is something along the lines of =IF(A:A=1,=COUNTIF(B:B,"Banana"),"")
I'm constantly adding in new cells aswell.
I only want the count the number of times a specific text has banana next to it.
How can I do this?
Use COUNTIFS() formula for matching multiple criteria in multiple ranges.
=COUNTIFS(A1:A4,1,B1:B4,"Banana")
This will count the number of time a cell in column A has 1 and Column B in the same row has Banana
=SUMPRODUCT((A:A=1)*(B:B="Banana"))
if you are checking for a string instead of "1", make sure to put it in quotes

Highlight duplicates, ignoring same row

I have a worksheet containing names in 2 dimensions. Each row represents a general location, every other column represents a specific slot in that location (each location has the same number of available slots), alternating with a parameter belonging to that name. There is a name in each cell. Here's a simplified version to show what my data looks like:
Location 0 ( ) 1 ( ) 2 ( ) 3 ( )
Garden Tim 3 Pete 1 Oscar 1 Lucy 2
Room1 Lucy 1 Tim 1 Lucy 5 Anna 1
Kitchen Frank 1 Frank 2 Frank 1 Lucy 1
What I want to achieve is to highlight (using conditional formatting, I'm open to alternative methods though) each entry that also appears in another row. So basically it should highlight duplicates, but ignore duplicates in the same row. The first row and column are to be excluded from the operation (no big deal, I just don't select them), as are the parameter columns (this is a big deal, as this pretty much breaks everything I've tried including the first answers given). I have access to the entire meaningful data area (all cells containing names) by the name "entries" and all meaningful entries in a given row by the name "row".
In my example above, all Tim and Lucy entries should be highlighted because they have duplicates in other rows. Pete, Oscar and Anna are unique, so they're not highlighted. Frank, while having duplicates, only has them in the same row, no other row contains Frank, so he should not be highlighted. Excel's own highlight duplicates would highlight Frank, while handling all the others correctly.
How can I modify the conditional formatting's behaviour to ignore duplicates in the same row?
The following formula (thanks to #Dave) resulted in a #VALUE! error:
=(COUNTIF(entries;B2)-COUNTIF(row;B2))>0
or you could just do (no need for an IF() when used in Conditional Formatting Formula box:
=COUNTIF($B$2:$I$4;$B2)>COUNTIF($B2:$I2;$B2)
This single formula should prevent the parameters from being highlighted
select B2:I2 and
put this (exactly) in the conditional formatting box: =AND(NOT(ISNUMBER(B2));COUNTIF($B$2:$I$4;B2)>COUNTIF($B2:$I2;B2))
Something like this:
=(COUNTIF($B$2:$E$4,B2)-COUNTIF($B2:$E2,B2))>0
The first countif counts all instances in the range, the second one subtracts the count of entries in the row. If there are more instances in the entire range than in the row it returns true

Return value of last match

I need a formula to return the value of Data for the last match of "Text". Row number is also acceptable. Macro is NOT acceptable. Name column is unsorted and cannot be sorted!
Only column "Name" is used as lookup value. I would rather use a/multiple helper column(s) instead of an array formula.
Row Name Data
1 Joe 10
2 Tom 20
3 Eva 30
4 Adam 40
5 Tom 21
LARGE only works with numbers, and VLOOKUP only returns the first match. LOOKUP only works sometimes, so its out too.
So if I wanted the last match for "Tom" then it should return "21".
Array formulas could be avoided with a helper column.
Suppose to have in F1 the name to match (i.e. Tom)
In the helper column row C2 enter
=IF(A2<>$F$1,0,row())
Then copy the formulas along your data.
Now the column C contains 0 for the unmatched names and the row number for the matched ones. Maxing the column yield the row of the solution.
Now the result is simple a matter of using the correct offset with the function offset:
=OFFSET(B1,max(C:C)-1,0)
PS: my copy of excel is in italian, so I can't test this english translaction of the formulas.
I think it's the easiest way to make it.
=LOOKUP("Tom";A2:B7)
Create a column with an array formula (enter it with Ctrl+Shift+Enter):
=VLOOKUP(MAX(IF($B$2:$B$6=B2, $A$2:A$6, 0)), $A$2:$C$6, 3, FALSE)
To make sure you did it right, click on the cell, and the formula should be shown encased in curly brackets ({}).
Note: This assumes that "Row" is in A1.
I have come up with a solution, but it requires that numbers in Data are concurrent, like so
Name Data
Joe 1
Tom 1
Eva 1
Adam 1
Tom 2
Tom 3
Eva 2
But thats okay, since that my data looks like that anyway. So if Name is used before then it must be the old highest +1 aka concurrent.
Name is A1 and Data is B1, and this formula goes into C2:
FLOOR(SQRT(2*SUMIF(A2:A7,A2,B2:B7)),1)

Resources