find out if cell contains one of several phrases

I need to parse out some data in excel and I hit a bit of a roadblock but if I can some kind of help with a formula that does this :



I want to test cell A1 to see if it contains any of the following phrases :

"Partially"

"Not Arrived"

"Arrived"

"Completely"



Cell A1 contains all of the text below in this box :

022-03142452 YYZ LHR 5 20.0 .01 Partially assigned to the booked flight. XCM YUL 3



If the cell contains "Partially", then I want the result to show "1"

If the cell contains "Not Arrived", then I want the result to show "2"

etc...



Appreciate any assistance,

txs,

FB

Posted on Jan 30, 2016 6:30 PM

Reply
15 replies

Jan 31, 2016 10:22 AM in response to Barry

as it turns out, I need the position number of where the found criteria is stored in the text string. In the example in cell A1, "Partially" would start at position number 33 I think. So I need another formula to tell me at what spot the text is found in the string.


This should do the trick if I can nail this down.


you boys have another one for me ? _~_

Jan 31, 2016 11:29 AM in response to furbreath

If you don't need instantaneous, totally automatic updating I find that a script can be a little easier for this sort of operation.


Say you have something like this with the text in column A. You can have a script fill out columns B and C:


User uploaded file


To run, just copy-paste into Script Editor (in the Applications folder) click once in the table, and click the triangle 'run' button.


SG


set searchPhrases to {"partially", "not arrived", "arrived", "completely"}


tell application "Numbers"

tell front document to tell active sheet to tell table 1

repeat with r from 1 to count rows

repeat with i from 1 to count searchPhrases

if cell ("A" & r)'s value contains searchPhrases's item i then

set cell ("B" & r)'s value to i

set cell ("C" & r)'s value to ¬


offsetof (searchPhrases'sitemi) in ¬

(cell ("A" & r)'s value as text)

exit repeat

end if

end repeat

end repeat

end tell

end tell



Or if you have only one cell to analyze:



set searchPhrases to {"partially", "not arrived", "arrived", "completely"}

set targetCell to "A1"


tell application "Numbers"

tell front document to tell active sheet to tell table 1

repeat with i from 1 to count searchPhrases

if celltargetCell'svalue contains searchPhrases'sitemi then

set cell "B1"'s value to i

set cell "C1"'s value to ¬


offsetof (searchPhrases'sitemi) in ¬

(cell targetCell's value as text)

exit repeat

end if

end repeat

end tell

end tell

Jan 31, 2016 12:55 PM in response to t quinn

thanks Quinn, I wasn't sure what that part was doing. I'm having trouble modifying the formula though to do a search for the criteria instead of placing a value. I realize all I have to do is do a search for each criteria instead of the 1,2,3,4 that's in there but I keep getting an error... I'm more familiar with excel so I know its some kind of bracket or comma issue. Can someone modify the formula for me pretty please?

Jan 31, 2016 1:52 PM in response to furbreath

Ok, I think I got it :


IF(IFERROR(SEARCH("Partially", A22,start-pos), 0)>0, (SEARCH("Partially", A22)),IF(IFERROR(SEARCH("Not Arrived", A22,start-pos), 0)>0, (SEARCH("Not Arrived", A22)),IF(IFERROR(SEARCH("Arrived", A22,start-pos), 0)>0, (SEARCH("Arrived", A22)),IF(IFERROR(SEARCH("Completely", A22,start-pos), 0)>0, (SEARCH("Completely", A22)),""))))

Jan 31, 2016 2:10 PM in response to t quinn

good idea Quinn,


Here is a sample of what might be in cells A1 through to A4 :


022-39567780 YYZ CDG 7 1091.0 2.94 Completely assigned to the booked flight. SCR LOGISTICS CDA INC 2

022-36952915 YYZ NTE 7 841.0 2.22 Goods have arrived at the station. BEMACER 2

022-39549720 YYZ SXB 7 369.0 .47 Completely assigned to the booked flight. ORC OVERSEAS RETRO CONSOLIDATORS 3

023-39147743 YYZ TLS 5 803.0 2.65 Completely assigned to the booked flight. STL CARGO AIR CARGO LOGISTICS INC 1


I need to parse out all what is considered data so that I can manipulate it further with formulas. As an example this is how I would like the first line to be separated :


022-39567780 YYZ CDG 7 1091.0 2.94 Completely assigned to the booked flight. SCR LOGISTICS CDA INC 2

Jan 31, 2016 3:54 PM in response to furbreath

Hi Furbreath,


This can be done but it is tedious and awkward to do. Having the data separated by multiple spaces does not make it easier to access later on. Patterns in your data that are consistent can be used. Is the initial number code always the same length, Are your sentences always the same 4, does the first number always only have one digit after the dot does the next always have 2, are ther only 3 periods in each line?


You are still not providing the big picture here. How are you using each ofthese pieces of data? If there are some you don't need don't spend the time teasing them out. Check out the functions available under Text in the function browser. in additon to the ones Barry mentionsed above examine LEFT(), MID() and RIGHT().


quinn

Jan 31, 2016 4:11 PM in response to furbreath

furbreath wrote:


Here is a sample of what might be in cells A1 through to A4 :


022-39567780 YYZ CDG 7 1091.0 2.94 Completely assigned to the booked flight. SCR LOGISTICS CDA INC 2

022-36952915 YYZ NTE 7 841.0 2.22 Goods have arrived at the station. BEMACER 2

022-39549720 YYZ SXB 7 369.0 .47 Completely assigned to the booked flight. ORC OVERSEAS RETRO CONSOLIDATORS 3

023-39147743 YYZ TLS 5 803.0 2.65 Completely assigned to the booked flight. STL CARGO AIR CARGO LOGISTICS INC 1


I need to parse out all what is considered data so that I can manipulate it further with formulas. As an example this is how I would like the first line to be separated :


022-39567780 YYZ CDG 7 1091.0 2.94 Completely assigned to the booked flight. SCR LOGISTICS CDA INC 2


Assuming your sample is representative of your data, i.e. you have strings that you need to parse into separate columns, you will probably find it easier to use a script.


The one below will do this:


User uploaded file


To use, you copy-paste the script into Script Editor (in the Applications > Utilities folder), and in this example select cells A1:A4 (the ones with the strings you need to parse) and click the 'run' button. After the prompt in this example I clicked once in cell B1 and typed command-v to paste. You could paste somewhere else as well. That's it! Post back if you have any problems.


SG


tell application "Numbers"

tell front document to tell active sheet

tell (first table whose selection range's class is range)

set selRng to selection range

set pasteStr to ""

repeat with c in selRng's cells

set pasteStr to pasteStr & my parseText(c'svalue) & return

end repeat

end tell

end tell

end tell

set the clipboard topasteStr

display notification "Click once in Numbers cell and command-v to paste"

return pasteStr


to parseText(textToParse)

try

set col1 to textToParse's text 1 thru 12 --> "022-39567780"

set col2 to textToParse'sword 3 --> "YYZ"

set col3 to textToParse'sword 4 --> "CDG"

set col4 to textToParse'sword 5 --> 7

set col5 to textToParse'sword 6 --> "1091.0"

set col6 to textToParse'sword 7 -->"2.94"

set col8 to textToParse's characters ((offset of ". " in textToParse) + 2) thru -1 as text ¬


-->"SCR LOGISTICS CDA INC 2"

set col7Start to (offset of col6 in textToParse) + (length of col6) + 1 --> 37

set col7End to (offsetofcol8intextToParse) - 2 --> 79

set col7 to textToParse'scharacterscol7Start thru col7End as text ¬


--> "Completely assigned to the booked flight."

return col1 & tab & col2 & tab & col3 & tab & col4 & tab & col5 & tab & col6 & tab & col7 & tab & col8

on error

display dialog "Select only cells with data you want to parse." buttons "Cancel"

end try

end parseText

Feb 4, 2016 10:41 AM in response to t quinn

The scripts are good to know however I need the results to show immediately so formulas are the way to go for me. Anyhow, most of it I already did and what I learned from you good folks helped me complete the rest...so I have exactly what I need for now - all the data parsed out so I can manipulate it further. I basically need quick access to total weights, individual weights & volumes, total volumes, etc.

Once I have these in their own cells I can expand my worksheet further by plugging in other fixed criteria. Basically I put this together to avoid a lot of last minute calculations and to limit possible errors under pressured times when I will need these numbers. I also plan on importing other data in the same format and to quickly identify what has changed.


I should be able to build upon my worksheet from here on since I have everything separated in each cell properly.


thanks a lot for everyone's help. This place rocks!

Feb 4, 2016 12:37 PM in response to furbreath

furbreath wrote:


The scripts are good to know however I need the results to show immediately so formulas are the way to go for me.


Actually, I wouldn't think of this as an either-or situation. A script can be easier for splitting a string into separate cells. It does its thing in a second or so. Formulas are then applied to sum, count, etc.


I guess your workflow and solution will remain a mystery.🙂 Glad you were able to find something that works for you.


SG

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

find out if cell contains one of several phrases

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.