+ Reply to Thread
Results 1 to 8 of 8

Extract word after specifying blank space

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    06-24-2012
    Location
    Australia
    MS-Off Ver
    Office365
    Posts
    309

    Extract word after specifying blank space

    Hi Expert,

    In a given cell I have following sample data that runs in thousands rows but in one column

    Task is to pull out any word (DXB or ABU in this case) that is 3rd from right, only if cell has 4 blank spaces in between two words or cell has 5 words in total

    SYD EK DXB EK SYD
    ADL EK DXB EK DEL
    ISB EY ABU EY MEL




    Task is to pull out 5th word (LGW or LON in this case) , only if cell has 8 blank spaces in between two words or cell has 9 words in total

    PER EK DXB EK LGW EK DXB EK PER
    SYD EK DXB EK LON EK DXB EK MLE

    Rows runs in mix of above two

    Currently I use following function to pull out specific words

    =IF(COUNT(SEARCH("DXB",A1)),"DXB"," ")

    Request for any function that may be able to assist based on blank spaces

    Thanks
    Karnik

  2. #2
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: Extract word after specifying blank space

    case 1:
    Formula: copy to clipboard
    =IF(ISERROR(SEARCH(CHAR(127),SUBSTITUTE(A10," ",CHAR(127),4))),"",MID(A10,SEARCH(CHAR(127),SUBSTITUTE(A10," ",CHAR(127),2))+1,SEARCH(CHAR(127),SUBSTITUTE(A10," ",CHAR(127),3))-SEARCH(CHAR(127),SUBSTITUTE(A10," ",CHAR(127),2))))
    case 2:
    Formula: copy to clipboard
    =IF(ISERROR(SEARCH(CHAR(127),SUBSTITUTE(A15," ",CHAR(127),8))),"",MID(A15,SEARCH(CHAR(127),SUBSTITUTE(A15," ",CHAR(127),4))+1,SEARCH(CHAR(127),SUBSTITUTE(A15," ",CHAR(127),5))-SEARCH(CHAR(127),SUBSTITUTE(A15," ",CHAR(127),4))))


    change A10 and A15 suitable.

    Edit:
    Formula checking spaces from left to right.
    Logical test is changed to LEN(A1)-LEN(SUBSTITUTE(A1," ",""))=4 or 8
    MID(...) can be defined as NAME (e.g. ShortString and LongString) in Name Manager, so formula will be shorter and clear
    Maybe someone else will give you shorter solution

    formula for both cases:
    Formula: copy to clipboard
    =IF(LEN(A1)-LEN(SUBSTITUTE(A1," ",""))=4,MID(A1,SEARCH(CHAR(127),SUBSTITUTE(A1," ",CHAR(127),2))+1,SEARCH(CHAR(127),SUBSTITUTE(A1," ",CHAR(127),3))-SEARCH(CHAR(127),SUBSTITUTE(A1," ",CHAR(127),2))),IF(LEN(A1)-LEN(SUBSTITUTE(A1," ",""))=8,MID(A1,SEARCH(CHAR(127),SUBSTITUTE(A1," ",CHAR(127),4))+1,SEARCH(CHAR(127),SUBSTITUTE(A1," ",CHAR(127),5))-SEARCH(CHAR(127),SUBSTITUTE(A1," ",CHAR(127),4))),""))
    Last edited by sandy666; 02-25-2016 at 08:53 PM.

  3. #3
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: Extract word after specifying blank space

    Or try this
    Enter formula in B1 and copy down

    Formula: copy to clipboard
    =IF(LEN(A1)-LEN(SUBSTITUTE(A1," ",""))=4,TRIM(MID(SUBSTITUTE(A1," ",REPT(" ",50)),50*2,50)),TRIM(MID(SUBSTITUTE(A1," ",REPT(" ",50)),50*4,50)))


    v A B
    1 SYD EK DXB EK SYD DXB
    2 ADL EK DXB EK DEL DXB
    3 ISB EY ABU EY MEL ABU
    4 PER EK DXB EK LGW EK DXB EK PER LGW
    5 SYD EK DXB EK LON EK DXB EK MLE LON
    If you like my answer please click on * Add Reputation
    Don't forget to mark threads as "Solved" if your problem has been resolved

    "Nothing is so firmly believed as what we least know."
    --Michel de Montaigne

  4. #4
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: Extract word after specifying blank space

    @AlKey,
    very nice formula but working with more then 8 spaces and more then 9 words.

    case 2: only if cell has 8 blank spaces in between two words or cell has 9 words in total,
    Quote Originally Posted by Karnik View Post
    Task is to pull out 5th word (LGW or LON in this case) , only if cell has 8 blank spaces in between two words or cell has 9 words in total
    Karnik
    EDIT:
    I have modified a little your formula:
    Formula: copy to clipboard
    =IF(LEN(A1)-LEN(SUBSTITUTE(A1," ",""))=4,TRIM(MID(SUBSTITUTE(A1," ",REPT(" ",LEN(A1))),LEN(A1)*2,LEN(A1))),IF(LEN(A1)-LEN(SUBSTITUTE(A1," ",""))=8,TRIM(MID(SUBSTITUTE(A1," ",REPT(" ",LEN(A1))),LEN(A1)*4,LEN(A1))),""))
    Last edited by sandy666; 02-25-2016 at 10:01 PM.

  5. #5
    Forum Contributor
    Join Date
    06-24-2012
    Location
    Australia
    MS-Off Ver
    Office365
    Posts
    309

    Re: Extract word after specifying blank space

    Hi Sandy666 and Alkey

    Thanks for your time and expertise , solution works brilliantly
    Cheers
    Karnik

  6. #6
    Forum Contributor
    Join Date
    06-24-2012
    Location
    Australia
    MS-Off Ver
    Office365
    Posts
    309

    Re: Extract word after specifying blank space

    Hi Expert,
    I am back again with same issue, but different challenge

    Function for cell that contains fix data characters 17 (including blank space ) given below in 1st 6 rows to pull out only last 3 characters only
    Function will ignore cell that has more that 17 character cells e.g. last to rows

    DATA RESULTS REQUIRED
    SYD EY AUH EY BEG BEG
    SYD VA SIN VA CDG CDG
    SYD VA SIN VA CDG CDG
    BNE TG BKK TG BNE BNE
    BNE TG BKK TG BNE BNE
    SYD TG BKK TG SYD SYD



    BNE DL LAX DL YVR DL YYC DL SLC DL LAX DL BNE (to be ignored)
    PER EY AUH EY LHE EY AUH EY PER (to be ignored)


    Thanks in advance

  7. #7
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,251

    Re: Extract word after specifying blank space

    Hey Karnik,

    How about something like this in B2 and pull it down:

    =If (Len(A2)>17,"",Right(A2,3))
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  8. #8
    Forum Contributor
    Join Date
    06-24-2012
    Location
    Australia
    MS-Off Ver
    Office365
    Posts
    309

    Re: Extract word after specifying blank space

    Hi MarvinP,

    It works!
    Thanks for simple solution, in fact I will use modify command to pull out desired results
    Cheers
    Karnik

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Extract first word and last numbers after space
    By ammartino44 in forum Excel General
    Replies: 10
    Last Post: 07-29-2015, 01:48 PM
  2. Is there a word macro to help me (1) combine different word files and (2) add space?
    By studyboymark in forum Word Programming / VBA / Macros
    Replies: 0
    Last Post: 03-05-2015, 03:19 AM
  3. Extract text between # and space
    By bp2010 in forum Excel General
    Replies: 3
    Last Post: 12-21-2010, 07:48 PM
  4. Extract text with space
    By maxthebear in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-01-2009, 08:01 PM
  5. Replies: 13
    Last Post: 05-06-2009, 07:33 AM
  6. Replies: 2
    Last Post: 06-22-2005, 08:05 PM
  7. Replies: 2
    Last Post: 02-11-2005, 06:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1