+ Reply to Thread
Results 1 to 11 of 11

extract last 2 words of cell

  1. #1
    Valued Forum Contributor
    Join Date
    11-27-2013
    Location
    Brooklyn, NY
    MS-Off Ver
    Office 365
    Posts
    1,172

    extract last 2 words of cell

    Hi.
    How do I write a macro to extract the last two words of a cell?

  2. #2
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: extract last 2 words of cell

    Try:
    Please Login or Register  to view this content.
    let Source = #table({"Question","Thread", "User"},{{"Answered","Mark Solved", "Add Reputation"}}) in Source

    If I give you Power Query (Get & Transform Data) code, and you don't know what to do with it, then CLICK HERE

    Walking the tightrope between genius and eejit...

  3. #3
    Valued Forum Contributor
    Join Date
    11-27-2013
    Location
    Brooklyn, NY
    MS-Off Ver
    Office 365
    Posts
    1,172

    Re: extract last 2 words of cell

    Thanks but how do I insert it in a code? You know, with sub and end sub. Let's use cell A1 as the active cell.

  4. #4
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: extract last 2 words of cell

    Depends what you're doing with the output. Tell me what you're trying to do.

  5. #5
    Valued Forum Contributor
    Join Date
    11-27-2013
    Location
    Brooklyn, NY
    MS-Off Ver
    Office 365
    Posts
    1,172

    Re: extract last 2 words of cell

    Cell A1 has the sentence "Hi, how are you doing?"
    How do I display in cell B2 "You doing?" extracting these last two words only?
    *Please note that the sentence in Cell A1 can vary.

  6. #6
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: extract last 2 words of cell

    Enter that function from my earlier post into a standard module.

    In B2, use formula:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

  7. #7
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: extract last 2 words of cell

    And just for fun (and because I hate fixing values into functions), here's a further function where you can specify the number of words to return:

    Please Login or Register  to view this content.
    Use as:
    A
    B
    1
    Hi, how are you doing? Hi, how are you doing?
    2
    =last2words(A1) you doing?
    3
    =lastxwords(A1,3) are you doing?

  8. #8
    Valued Forum Contributor
    Join Date
    11-27-2013
    Location
    Brooklyn, NY
    MS-Off Ver
    Office 365
    Posts
    1,172

    Re: extract last 2 words of cell

    Wow thanks. I'm still new to VBA so how do I enter what you posted into a regular code that I can hit straight from the excel sheet?

  9. #9
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: extract last 2 words of cell

    As I said, just paste the function code into a standard module of your workbook, then that function (a UDF, or User Defined Function) is then available for you to use in the worksheets of that workbook.

  10. #10
    Valued Forum Contributor
    Join Date
    11-27-2013
    Location
    Brooklyn, NY
    MS-Off Ver
    Office 365
    Posts
    1,172

    Re: extract last 2 words of cell

    Thanks OllyXLS, this is a major break though in my excel experience!
    Best of luck to you;-)

  11. #11
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: extract last 2 words of cell

    Glad it's helped, and that you've learned something Thanks for the feedback!

+ 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. Replies: 7
    Last Post: 02-25-2014, 02:00 AM
  2. [SOLVED] Extract first two words of a cell
    By letangerang58 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-05-2013, 01:12 PM
  3. How can i extract specific words from a cell?
    By mikey42979 in forum Excel Formulas & Functions
    Replies: 30
    Last Post: 06-17-2013, 12:27 PM
  4. Extract particular words from a cell
    By DeepakS in forum Excel General
    Replies: 2
    Last Post: 08-22-2011, 08:58 AM
  5. Can I extract certain words from inside a cell?
    By kufta4 in forum Excel General
    Replies: 4
    Last Post: 03-30-2011, 11:01 AM

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