Formula for excel - excel

Help me please, to find a formula for excel, which takes all the words in the text (for example, text from column A) and gives all the words from the text without repeating in a column B.
For example,
Column A
Text
Although simplicity is a virtue, theories regarding pedagogy do not work in practice if they are black and white. To say that the best way to teach is only to praise positive actions and to ignore negative ones is like saying that strawberries reduce one’s risk for cancer so people should cut apples out of their diet and only eat strawberries. In both situations, there does not have to be a choice.
Column B - Words from text
Although
simplicity
is
a
virtue,
theories
regarding
pedagogy
do
not
work
in
practice
if
they
are
black
and
white.
To
say
that
the
best
way
to
teach
is
only
to
praise
positive
actions
and
to
ignore
negative
ones
is
like
saying
that
strawberries
reduce
one’s
risk
for
cancer
so
people
should
cut
apples
out
of
their
diet
and
only
eat
strawberries.
In
both
situations,
there
does
not
have
to
be
a
choice.

This is a rather complex thing for a single formula .... here's a method ...
part 1: splitting a text into single words:
A1: your text
A3: =SUBSTITUTE(A1,",","") .... removing commas
A5= =SUBSTITUTE(A3,".","") .... removing full stops (repeat this for other punctations you might have
A8: constant value 0
A9: =FIND(" ",$A$5,A8+1) .... find the first blank in $A$5 after the position indicated by the cell above .... copy this formula down until you get the first #VALUE error
B9: =MID($A$5,A8+1,A9-A8-1) .... extract the word between previous and this blank position .... copy this formula down until you get the first #VALUE error
when you are happy with your split list, copy/paste as values the list and do some headers
part 2: finding uniques words:
You need to find each unique word exactly once. A method strictly without VBA would consist of the following:
sort the text in column B ascending
enter in C8: =IF(B8=B7,C7+1,1) and copy down to end of list ... you create a "running number starting with 1 and continuing to increment as long as the word remains the same
autofilter column C for value = 1 ... this will display the first occurence of each word
copy / paste the filtered list to whereever you want to store it for further processing ... I recommend a sheet different from your raw data
You can restore the original sort order of the result by sorting on the numeric values in column A.
As you can see in the example of words "in", "to", this method is case insensitive. A limitation is a possible false seperation between "ones" and "one's" ... this needs to be decided.

You can try this formula:
=TRIM(MID(SUBSTITUTE($A$1;" ";REPT(" ";LEN($A$1)));1+(ROW(A1)-1)*LEN($A$1);LEN($A$1)))
Assuming test in A1, write formula in B1 and copy down till you got last word
Depending on your regional settings you may need to replace ";" by ","

Related

Sort text alpha numerically in excel

I have part number data in a spreadsheet that has been converted to text data (not numeric as there are letters) that I need to sort alpha numerically. I have read enough that this appears to be almost impossible due to nulls (I have none of these) dashes (I have tons of these). As you will see below, there are multiple letters and numbers in different locations in the field.
MS16624-2066
RWR80S
02-6009-23
23032-1910
31708-1370
11SM1-T
111SM1-5
The final result required is:
MS16624-2066
RWR80S
02-6009-23
11SM1-T
111SM1-5
23032-1910
31708-1370
I have tried as much as I could by looking at the sorts in this forum, but have had no luck. Can anyone suggest a working approach?
Assuming part numbers are in ColumnA starting in A1, in B1:
=SUBSTITUTE(A1,"-","")
Copy down to suit then Copy ColumnB and Paste Special, Values over the top.
Apply Text to Columns, Fixed width to ColumnB and choose character by character (positions 1 to 11 for your example).
Then sort A:M on ColumnC descending and move the rows with C numbers below the C letters.
You may then choose to delete ColumnsB:M.

Excel: How to copy specific cell data (zip codes) into a new column

I have two columns of cells that have irregularly formatted addresses.
I need:
1) just the zip codes to be copied into a new column;
2) the rows that do not contain zip codes to be either highlighted or empty so that I can easily identify which ones are missing.
This seems like it would be simple to do, but I can't figure out how to have Excel just find all instances of 5 consecutive numbers. Currently they are formatted as text so that the zero's are displayed. Any help greatly appreciated.
Here's what it would be to start with:
Here's what it would look like when done (highlighting optional):
You don't have Regular Expression in normal Excel. You would have to go into VBA to do that. However, for your case, there's an easy pattern: notice how the zip code is after the last space, and it's always 5 digits long? The challenge then become finding the index of this last space and extract the 5 characters that follow it. It will be clearer if you split them into 2 formula
// C3 (index of last space character):
=FIND("|",SUBSTITUTE(B3," ","|",LEN(B3)-LEN(SUBSTITUTE(B3," ",""))))
// D3, the 5 characters after that.
// Return an empty string if the address doesn't match the pattern
=IFERROR(MID(B3,C3+1,5),"")
Another approach to what Zoff Dino wrote is to break it out a bit as shown below:
In cell C3 enter the formula you see in the formula bar
Drag that down the row set and over 1 column (so it runs for column B as well)
In column use this formula: =IF(AND(C3="",D3=""),"",IF(C3="",D3,C3)) and drag it down.
This will account for all possible situations you have shown and not error out on you (unless other patterns emerge).
You can then use conditional formatting to highlight the rows with no zip code as shown in the picture:

Excel Search and Replace string with vlookup

I have a excel sheet where I have columns that say
"I like TSX but I prefer 350"
"I like beamer but I am fan of S-Class"
I want to replace this with
"I like Acura but I prefer BMW"
"I like BMW but I am fan of Mercedes"
I have another excel sheet with the match and replace values. For example
TSX, Acura
TL, Acura
350 BMW
Beamer, BMW
etc.
I know how to use vlookup, but this is way advance for me. Any help? Thanks you.
Rather than use vlookup at all, if you don't have many types of cars you could simply use SUBSTITUTE. Works as
=SUBSTITUTE(A1, "TSX", "ACURA")
Then wrap it many times, once for each possibility:
=SUBSTITUTE(SUBSTITUTE(A1, "TSX", "ACURA"),"S-CLASS", "MERCEDES"))
If you have many possibilities, this will either need 2 helper columns, or vba. Let me know if that's the case. Basically without vba you will need to search for the first term in 1 column, then put the 2nd term in the second formula, then replace the 1st term with a vlookup'd equivilent, then replace the 2nd term with a vlookuo'd equivilent (using substitute as above).
Edit
Reading the q again it seems there are many possibilities, so we will need to use two helper columns and areay formulas to solve. VBA is likely better, but In on my phone so cant error test anything, and you might not want vba anyway.
The principle for these helper columns is going to be to find which 2 vehicles exist in the text. Once you know which two exist, you can simply replace both as above.
The first stage of the formula we will be putting in colns B and C, (assuming your 'vlookup text' is in columns A and B on sheet2 from rows 1 to 100) is:
=If(iserror(search($A1,sheet2!$A$1:$A100)),"",row(sheet2!$A$1:$A$100))
This is an array formula, which works on each cell in the range you give it. To confirm it, press CTRL + SHIFT + ENTER instead of just ENTER. It gives you an array of results, that you need to collapse into a single answer. so in column B, wrap it in a MIN function. For column C, wrap it in a Max function.
So now column B shows the row number of 1 matching term, and row C shows the row number of the 2nd matching term.
So now in column D, we know the row number of the first match, the first replacement term, and thend match and replacement term. Replace everything as follows:
=Substitute(substitute(A1,INDEX(SHEET2!$A$1:$A$100, B1),INDEX(SHEET2!$B$1:$B$100, C1)),INDEX(SHEET2!$A$1:$A$100, C1),INDEX(SHEET2!$B$1:$B$100, B1)))
Make sure you confirm with CTRL SHIFT ENTER instead of just enter.
Apologies if this isnt formatted 100%; Im on my phone and will error check it later if it causes problems. Let me know if you have questions about how this works.

How to apply conditional formatting in excel for multiple text conditions

I am trying to delete a large number of cases (Tweets) in excel based on certain words. Only one word has to be present for me to delete it.
example:
blue big bird
orange bird flies
elephant is angry
cool cat in tree
List of words I would want to delete on: bird, blue and cat. Therefore, the function should delete 1. 2. and 4, no matter if all words are present, or only one or two. Currently I only know how to format it based on one word, but I have roughly 50 words per file to filter on, so it would save a lot of time to have a function. I am not sure which function works for this? I already have a list of the words I want to delete on in another spreadsheet.
The formula you are searching is
=IF(SUM(COUNTIF(B2,"*"&{"cool","orange"}&"*"))>0,B2,"")
where B2 is a cell in the row with your values (e.g. 1. blue big bird).
Apply this for every cell and you get the cell value for every hit and "" for no hit.
If you already have a list of words in a spreadsheet, you can assign that list a range name, since 50 words are a bit much for a formula and hard to maintain.
Consider the following screenshot. The highlighted range has the range name TriggerWords.
The formula in cell B1 is
=IF(SUM(COUNTIF(A1,"*"&TriggerWords&"*"))>0,"",A1)
which is an array formula that must be confirmed with Ctrl-Shift-Enter. Then copy down.

If cell contains 1 or more keywords, change value of a different cell

I have a column with some string description in it.
for example:
Bob davids
mowing the lawn
tipping cows
In addition I will have on a different sheet or column a list of keywords
For example work keyword list 1:
davids
work
play keyword list:
mowing
cows
So as the main column is populated with these text strings, I would like them checked automatically each keyword list to see if those words exist, and when it finds a match, place the title of the list (work/play) in the cell next to it.
I know this is possible in VBA and can even do it "on the fly" in SelectionChange function. But is this possible to do without VBA such as a conditional formatting?
This is pretty easy to do with just formulas, as long as you don't care too much about possibly improperly finding parts of words. Ignore that caveat for a second though. First, here is a formula that will tell you if any of several strings are found anywhere within a source string:
=OR(NOT(ISERROR(FIND(<array of strings to look for>,<string to look in>))))
This needs to be entered as an array formula for it to work. You do that by entering it with Ctrl-Shift-Enter. To understand how it works, consider what Excel does in evaluating a real example:
=OR(NOT(ISERROR(FIND({"a","b","c"},"q b q"))))
'FIND' finds the position of one string within another. When called with an array for the first argument, it will return an array of positions (or #VALUE! if the search string isn't found). You can trace the evaluation by entering that formula and then using the F9 key on expressions within it:
=OR(NOT(ISERROR({#VALUE!,3,#VALUE!})))
=OR(NOT({TRUE,FALSE,TRUE}))
=OR({FALSE,TRUE,FALSE})
=TRUE
So, for your example, say you had your strings you want searched in $B$6:$B$8, your work strings in $D$2:$D$3, and your play strings in $E$2:$E$3. You could put the formula
=OR(NOT(ISERROR(FIND(D$2:D$3,$B6))))
in cell D6, enter it as an array formula, and then drag it through the range D6:E8 to find which strings in B had work or play words in them. Then you could use those results to drive further formulas or conditional formatting.
However, as mentioned above, you'll note that any substring within the string being searched will get found, so
=OR(NOT(ISERROR(FIND({"a","b","c"},"bad"))))
will evaluate to TRUE. (And if your fun list includes "id", the "id" in "davids" will match.)
As is often the case with Excel, if you're doing something you understand with a limited data set, you might not care about this. But it can defeat an attempt to use this kind of formula as part of a general "application" that has users who don't know fancy array tricks or exactly what 'FIND' does. (You can sort of get around that by putting a space after your search words, etc., but that is just more mysterious voodoo waiting to be broken if you hand it someone else.) For a quick and dirty scan, though, it's fine.
I've put together another way of doing this for a small number. As was intimated, this gets cumbersome quickly.
Input the following into column A:
1: horse cow pig chicken
2: dog cat bird
3: fish cat
4: horse cat mouse
5: ape human dolphin
6: dog cat chipmunk
In Cell B1 enter the following (and copy into B2:B6):
=if(sum(iserror(find("cat",A1)),iserror(find("dog",A1)),iserror(find("fish",A1)),iserror(find("bird",A1)))<4,"House pet","")
The result in B1 and B5 should appear blank whereas the result in B2, B3, B4, and B5 should read "House pet".
Careful if the list of keywords gets too big. I used this successfully for short lists too (as implied in the question) but you have limited space to type all the possibilities if its too long - not to mention risk errors in the formula.
I couldn't get my arrays to work - thanks for the post above I'm going to go give this a try now too for my longer lists.
ps. Don't remember what I was doing with my OR ISERROR array but this array you've provided worked beautifully for my list of 80 keywords. Thanks!

Resources