Results 1 to 3 of 3

Extracting the nth word in Excel Document

Threaded View

cabinet12 Extracting the nth word in... 03-05-2019, 03:54 PM
mehmetcik Re: Extracting the nth word... 03-05-2019, 05:56 PM
cabinet12 Re: Extracting the nth word... 03-05-2019, 06:59 PM
  1. #1
    Registered User
    Join Date
    03-05-2019
    Location
    Minneapolis, MN
    MS-Off Ver
    MS Office 2010
    Posts
    25

    Post Extracting the nth word in Excel Document

    [code]I would like to get the below cod fixed in a new excel file. Is it possible to get this code preset in excel, that way I don't have to enter this code into each module when I want to use it?

    Extract nth word from text string with User Defined Function
    If you want to extract the second, third or any nth word from the text string, you can create a user defined function to deal with it.
    1. Hold down the ALT + F11 keys to open the Microsoft Visual Basic for Applications window.
    2. Click Insert > Module, and paste the following code in the Module window.
    Function FindWord(Source As String, Position As Integer)
    'Update 20131202
    Dim arr() As String
    arr = VBA.Split(Source, " ")
    xCount = UBound(arr)
    If xCount < 1 Or (Position - 1) > xCount Or Position < 0 Then
    FindWord = ""
    Else
    FindWord = arr(Position - 1)
    End If
    End Function
    3. Then save the code, in this example, I will get the third word from the string, so type this formula =findword(A2,3) into a blank cell B2, and then drag this cell's AutoFill handle to the range as you need. See screenshot:

    Note: In the above formula, A2 is the cell where you want to extract word from, the number 3 indicates the third word in the string that you will extract, and you can change them as you need.
    [code]
    Last edited by cabinet12; 03-05-2019 at 06:59 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Extracting data from Word document to populate Excel spreadsheet
    By Jegley in forum Word Programming / VBA / Macros
    Replies: 16
    Last Post: 03-15-2017, 08:50 AM
  2. Mail merge of Excel data to Excel document, not using a Word document
    By Howie D in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-23-2015, 07:35 AM
  3. Add text to Existing Word Document if it Doesn't exist create Word Document
    By unstable81 in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 01-10-2013, 12:15 AM
  4. Replies: 0
    Last Post: 06-15-2011, 02:22 PM
  5. Extracting data from Word document (Survey)
    By BartDeHertogh in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-21-2010, 10:34 AM
  6. [SOLVED] How do I convert a word document into a Excel document
    By gwiltz2 in forum Excel General
    Replies: 1
    Last Post: 10-22-2005, 03:05 PM
  7. [SOLVED] How do I convert Word document into an Excel document?
    By Jamie in forum Excel General
    Replies: 4
    Last Post: 04-07-2005, 05: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