+ Reply to Thread
Results 1 to 8 of 8

Extract First & Second Name into Variable

  1. #1
    Forum Contributor
    Join Date
    11-12-2012
    Location
    Jeddah, Saudi Arabia
    MS-Off Ver
    2010, 2013, 2016, Office 365
    Posts
    507

    Extract First & Second Name into Variable

    Hi,

    How can I extract First & Second name into variable. I have the below code which extracts First Name but I need to add the second name to it. If there is only First Name then extract First Name else First and Second.

    Please Login or Register  to view this content.

  2. #2
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: Extract First & Second Name into Variable

    Please Login or Register  to view this content.
    Last edited by skywriter; 10-28-2023 at 08:48 PM.
    Click the * Add Reputation button in the lower left hand corner of this post to say thanks.

    Don't forget to mark this thread SOLVED by going to the "Thread Tools" drop down list above your first post and choosing solved.

  3. #3
    Forum Contributor
    Join Date
    11-12-2012
    Location
    Jeddah, Saudi Arabia
    MS-Off Ver
    2010, 2013, 2016, Office 365
    Posts
    507

    Re: Extract First & Second Name into Variable

    @skywriter,

    Thanks, it's working. Can you please amend to fixed Range("C8")
    Attached Files Attached Files

  4. #4
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: Extract First & Second Name into Variable

    Thanks for the rep. points.
    I can't fix it without first knowing what's wrong with it and what you expect.
    It would be better to upload a workbook with a larger data set, 20 or so examples and what you expect and why.

  5. #5
    Forum Contributor
    Join Date
    11-12-2012
    Location
    Jeddah, Saudi Arabia
    MS-Off Ver
    2010, 2013, 2016, Office 365
    Posts
    507

    Re: Extract First & Second Name into Variable

    Thanks for your support, Nothing wrong in your code, it is working perfect. I have attached the worksheet, In simple sentence code should look for Range("C8") and extract the first and second name instead of Array (bbb, ccc, aaa)

    Anyway I have fixed it.

  6. #6
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: Extract First & Second Name into Variable

    My array was simply to create three example names as you did not include sample data.
    C8 in the sample workbook you attached contains "MAMAS Ports Services Co. Ltd." which does not fit the first name - last name request you originally made, hence my confusion.

  7. #7
    Registered User
    Join Date
    10-27-2023
    Location
    USA
    MS-Off Ver
    Office 365
    Posts
    11

    Re: Extract First & Second Name into Variable

    Try this-

    Please Login or Register  to view this content.
    Last edited by AliGW; 10-30-2023 at 07:21 AM. Reason: Code tags corrected.
    Thanks
    James

  8. #8
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: Extract First & Second Name into Variable

    @jamesmillere
    Why are you posting the code I wrote with "try this"?

+ 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. [SOLVED] Extract from a sentence of a variable length
    By Jayant shettigar in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 01-29-2023, 10:28 AM
  2. How to extract column and row into a variable?
    By cristiallx in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-08-2020, 10:11 AM
  3. VBA: Extract variable number of rows per variable number of phone numbers
    By redstone2830 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-17-2018, 09:22 PM
  4. [SOLVED] How to extract a piece of a string variable, and assign to a new variable
    By jmccoughlin in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-04-2015, 11:50 PM
  5. Extract First word from the variable
    By sriku in forum Excel General
    Replies: 3
    Last Post: 05-12-2014, 01:46 PM
  6. Extract position from variable
    By borgeklungerbo in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 04-21-2012, 12:01 AM
  7. Extract last name into a variable using VBA code
    By mikeburg in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 01-22-2006, 04:15 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