Excel: search if a specific text exists in a column - excel

I have two columns. Each cell in column A contains a full sentences and each cell in column B contains a word or phrase. I would like to check if the contents of each cell in column B appears in one of the cells in column A---it could appear in multiple cells in column A or in no cells. The output just needs to be a yes or no (and should be spit out in column C) for my purposes, but it would be neat to return the number of times each column B word came up somewhere in Column A.
So far I haven't figured out how to take a discrete string of letters (already printed in one cell) and search across a range in a column. Not sure if this is beyond the regular excel functionality.
Thanks very much for your help!

Use array formula like this:
=SUM(IF(ISERROR(SEARCH(B1,A:A,1)),0,1))
enter in formula bar then press CTRL+SHIFT+ENTER.
Hope this helps.
Put formula in C.

Try This :
=countif(a:a,"*" & b2 & "*")>0 gives you result in True/Flase
To get the occurrence
=countif(a:a,"*" & b2 & "*")
To get YES/NO
=if(countif(a:a,"*" & b2 & "*")>0,"YES","NO")

Related

Counting past occurrence given a classification

I have a Table just like the one in the picture below. I want to count the number of cells in the column Leg since the last entry, given a certain classification on the column Type.
For example, for the type KFT only, how many blank entries are there in the column Legendary since the last entry for Leg?
I know how to solve this issue creating helper columns. But given that I have too many types, I would have to create a helper column for each type, making my table too big given the amount of rows I have. Is there any way I can create a VBA function to perform this task for me, such that I only need one cell per type to let me know the amount of blank cells since last Leg entry for each type? Here is a short example of how my table looks, using only 2 types:
In this example, I need a formula with output 0 for MSG, since it has been 0 entries since the last Leg for MSG, and output 2 for UNG, since it has been 2 entries since the last Leg for UNG.
Thanks so much for the help!
Solution 1 Using single scary formula
Alright then. I think best solution to your problem is using helper column or VBA but if you really want to use just one formula, I've something for you. This formula is very very scary and someone might give you better solution also, but this formula does work.
In the below formula I've assumed data to be in range A2:F100. Change 100 to you number of rows of data. (change all 100's, best way will be to copy formula without = in an empty sheet and then FIND 100 and REPLACE ALL to your row number)
If you have listed Types in Column H starting from Cell H2 then in Cell I2 enter the following formul, drag/copy down as required.
=COUNTIFS(INDIRECT("F" & INDEX($A$2:$A$100,MAX(IF(($B$2:$B$100=H2)*($F$2:$F$100=1),ROW($B$2:$B$100)-ROW(INDEX($B$2:$B$100,1,1))+1)))+1 & ":F" & IF(INDEX($A$2:$A$100,MAX(IF(($B$2:$B$100=H2)*($F$2:$F$100=1),ROW($B$2:$B$100)-ROW(INDEX($B$2:$B$100,1,1))+1)))+1>INDEX($A$2:$A$100,MAX(IF(($B$2:$B$100=H2)*($F$2:$F$100=""),ROW($B$2:$B$100)-ROW(INDEX($B$2:$B$100,1,1))+1)))+1,100,INDEX($A$2:$A$100,MAX(IF(($B$2:$B$100=H2)*($F$2:$F$100=""),ROW($B$2:$B$100)-ROW(INDEX($B$2:$B$100,1,1))+1)))+1)),"",INDIRECT("B" & INDEX($A$2:$A$100,MAX(IF(($B$2:$B$100=H2)*($F$2:$F$100=1),ROW($B$2:$B$100)-ROW(INDEX($B$2:$B$100,1,1))+1)))+1 & ":B" & IF(INDEX($A$2:$A$100,MAX(IF(($B$2:$B$100=H2)*($F$2:$F$100=1),ROW($B$2:$B$100)-ROW(INDEX($B$2:$B$100,1,1))+1)))+1>INDEX($A$2:$A$100,MAX(IF(($B$2:$B$100=H2)*($F$2:$F$100=""),ROW($B$2:$B$100)-ROW(INDEX($B$2:$B$100,1,1))+1)))+1,100,INDEX($A$2:$A$100,MAX(IF(($B$2:$B$100=H2)*($F$2:$F$100=""),ROW($B$2:$B$100)-ROW(INDEX($B$2:$B$100,1,1))+1)))+1)),H2)
This is an array formula so commit it by pressing Ctrl+Shift+Enter.
Solution 2 Using Helper Columns
Assuming you listed all Types in Column H starting from Cell H2 then in Cell I2 enter the following array formula to get the last row from data for corresponding Type in Column H and Leg =1
=INDEX($A$2:$A$11,MAX(IF(($B$2:$B$11=H2)*($F$2:$F$11=1),ROW($B$2:$B$11)-ROW(INDEX($B$2:$B$11,1,1))+1)))+1
Then in Cell J2, enter the below array formula to get the last row from data for corresponding Type in Column H and Leg ="" (blank)
=INDEX($A$2:$A$11,MAX(IF(($B$2:$B$11=H2)*($F$2:$F$11=""),ROW($B$2:$B$11)-ROW(INDEX($B$2:$B$11,1,1))+1)))+1
Next, in Cell K2, enter the below formula to set last row if there's no row corresponding to particular type for which leg is blank (for example in my sample data ABC do not have empty Leg)
=IF(I2>J2,11,J2)
Finally, in Cell E2 enter the following formula to get Count
=COUNTIFS(INDIRECT("F" & I2 & ":F" & K2),"",INDIRECT("B" & I2 & ":B" & K2),H2)

Identify which cell in a row contains a specific text

I have a column compromising of text, I would like to search through that entire column to identify in which cell does the contents contain text that I am searching for.
Snip of the excel data
I need to search for the text in the first column and identify which cell in the final column contains the data I am searching for.
You use this formula,
=IfError(VLOOKUP (A2, A2:D25, 3,False),"")
This formula will search for value match with A2 in data range A2:D25, in Column 3 means in C,, if find pull the match otherwise return a Blank. U can write "Value not found" within quotes also.
Use the formula in some column , say I,
=IF(ISERROR(FIND($A$1,F1,1)),"",F1)
Drag down till the end of list. This will return what all matches A1 with column F. If you want to search for A2, change the formula to A2 and do the same. This cannot be done for all columns in A with all columns with F as there is a chance that the same string can be found in one or more cells in F.

Need to compare part of text in a range of cells to see if exists in another range of cells

Basically... I have 800+ names in columns B and C. I have another 700,000+ names in column A. So I want to check A1 to see if part of the text is found anywhere in B and C and then output the answer to D1.
For example... A1 has the name mike trout in it. Somewhere in b or c could be the name trout. I want D1 to output TRUE because a cell in b or c contained part of the text found in A1. If the names Mike or Trout are nowhere to be found in columns b or c, I want D1 to say FALSE. Can this be done? I've been searching online for hours and cannot come up with the correct formula that works. Thanks.
This is a slightly more complex version of this answer: https://stackoverflow.com/a/22754109/293078. Both use COUNTIF with wildcards. This one requires a helper column. Here's how it looks:
Column B has a formula that adds a space before and after the corresponding name in column A. The formula in B2 is:
=" " & A2 & " "
This gives means that we'll only get matches for full words, e.g., "Ted" won't match "Teddy Bear," but "Teddy" will.
As you described, columns C and D contain the names to search for. Finally, in E2, we have this array formula, which must be entered with ctrl-shift-enter:
=SUM(COUNTIF(B2,"* " & $C$2:$D$8 &" *"))>0
Drag the formulas in B2 and E2 down 700,000 rows and watch the magic happen.
I thought this would be hopelessly slow, but I just tried 700,000 rows and it finished in a few seconds.

Append row1 data to row 2

I need to append data of the alternate row like D1+D2 into Excel.
Please tell me how can I do that?
I have for example:
D1 = medical
D2 = Equipment
and I need:
D1 = medical Equipment
You can't put a formula in D1 while also retaining D1 as the source of the text for that formula. You mention alternate rows, so presumably you want D3 with D4 etc. Hence I'd suggest:
=D1&" "&D2 in Row1 of some other unused column,
then copy that down as far as required,
copy that other column and paste special / values over the top of ColumnD,
tidy up by deleting the 'spare' column,
and delete contents of cells in ColumnD of even row number.
& strings together the text (concatenates) but to insert a space as well you must separate it with double inverted commas at each end.
Insert a new column D. (moving old columns to the right)
Enter this formula in D1:
=E1 & " " & F1
If you are trying to combine the data from the two columns, the & symbol will let you do that. However, the formula can't be in either of the two columns you are trying to combine which is why I reccomended inserting a column.
If you, for some reason, can't insert this formula into a column and must work only inside of the original two columns let us know and we can post VBA code that can assist. However, it sounds like the formula approach will be the simplest solution.

Excel find duplicate cells in multiple columns

I have an Excel table with 4 columns and need to find the values that are the same in ALL 4 of the columns and put them aside. Trying to figure out how to accomplish this in Excel.
Example:
Column 1 Column 2 Column 3 Column 4
A1 B1 B1 A1
B1 C2 C1 B1
C2 D3 C2 C2
In this example, both B1 and C2 values comply and must be set aside.
Put this formula in cell D1 and drag and drop it till the end of your values:
=IF(AND(COUNTIF($B$1:$B$3,A1)>0,COUNTIF($C$1:$C$3,A1)>0,COUNTIF($D$1:$D$3,A1)>0),A1,"not found")
For the record, the french version:
=SI(ET(NB.SI($B$1:$B$3;A1)>0;NB.SI($C$1:$C$3;A1)>0;NB.SI($D$1:$D$3;A1)>0);A1;"not found")
To generate a list of values that appear in all four columns, try in cell F2:
=INDEX(A$1:A$3,MATCH(TRUE,COUNTIF(B$1:B$3,A$1:A$3)*COUNTIF(C$1:C$3,A$1:A$3)
*COUNTIF(D$1:D$3,A$1:A$3)*NOT(COUNTIF($F$1:F1,A$1:A$3))>0,0))
confirmed with CTRL+SHIFT+ENTER and fill down as far as needed (this assumes F1 is blank or contains unrelated data)
I couldn't get the above examples to work for myself, so I came up with another solution. Hopefully this will help someone else out there:
=IF(ISNUMBER(MATCH($A2, $B$2:$B$4, 0)), IF(ISNUMBER(MATCH($A2, $C$2:$C$4, 0)), IF(ISNUMBER(MATCH($A2, $D$2:$D$4, 0)), $A2, ""), ""), "")
This checks the value in "Column 1" ("A" column in excel) against the next 3 columns (B,C,D). If the value is present in all three it returns the A column value. If it is not present in all 3, it returns empty. If you would rather return something else, put that something in between the empty quotation marks.
For your data, enter in the lengths of the searched columns, B through D. For example, where it says, "$B$4", put in "$B$99" if the cells go down to 99, but it should work if you put in a generically high number, for example, 99999.
Put this in the row of the first value, so here that would be E2, and then copy it down to every row that has a value in column A.
The function works by just nesting IF statements, and can be expanded or contracted depending on how many columns you want to check against. The function can also be easily modified into a "check if in column B OR column C" function pretty easily.
here is an example for 1 value; I can't generalize since I did not see your data source
Sub test()
If (Range("D6").Value = Range("D6").Offset(0, 1).Value) Then
MsgBox "match"
End If
End Sub
you can also delete duplicates across multiple Columns by using DATA-> Remove Duplicates.

Resources