+ Reply to Thread
Results 1 to 7 of 7

Pulling a value from a string

  1. #1
    Registered User
    Join Date
    07-12-2012
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    57

    Pulling a value from a string

    Hello!

    I created a macro that opens a page as an excel sheet, grabs data from it, and inserts it into a cell.
    My problem is that one of the cells has an abundance of data that I don't need.

    The data that it puts into the cell looks like this: 0849940222,* Bill Myers ,* Thomas Nelson,*1997-10-02
    The only thing I need is the first name that shows up.
    The number at the beginning is always the same length, so I thought about using a trim function for that, but since names are not always the same length, I have no idea how to do the other end. Maybe get the value for commas and delete everything before the first and after the second...
    I also don't know how to do that in VBA.
    Any help would be appreciated!
    Cheers!

    (The data is the ISBN, Author, Publisher, and Date released)

  2. #2
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Pulling a value from a string

    take a look at the INSTR (In String) function of VBA
    Ernest

    Please consider adding a * if I helped

    Nothing drives me crazy - I'm always close enough to walk....

  3. #3
    Forum Contributor
    Join Date
    12-02-2009
    Location
    Akron, Ohio
    MS-Off Ver
    Excel 2010
    Posts
    208

    Re: Pulling a value from a string

    Quote Originally Posted by Ataraxicatom View Post
    Hello!

    I created a macro that opens a page as an excel sheet, grabs data from it, and inserts it into a cell.
    My problem is that one of the cells has an abundance of data that I don't need.

    The data that it puts into the cell looks like this: 0849940222,* Bill Myers ,* Thomas Nelson,*1997-10-02
    The only thing I need is the first name that shows up.
    The number at the beginning is always the same length, so I thought about using a trim function for that, but since names are not always the same length, I have no idea how to do the other end. Maybe get the value for commas and delete everything before the first and after the second...
    I also don't know how to do that in VBA.
    Any help would be appreciated!
    Cheers!

    (The data is the ISBN, Author, Publisher, and Date released)
    Use the text to columns function in the Data tab of excel 2010. Select a comma as the delimiter. Then use this formula on the resulting parsed strings:

    Please Login or Register  to view this content.
    Where Cell is the location of the parsed string such as A1 or B2, etc. that contains the first name.

  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: Pulling a value from a string

    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...

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

    Re: Pulling a value from a string

    Or to extend that a bit, you could use:
    Please Login or Register  to view this content.
    And use as:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    or
    Formula: copy to clipboard
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    07-12-2012
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    57

    Re: Pulling a value from a string

    Thanks for the quick replies, but I just needed a nudge. Using Judgeh59's suggestion, I created a simple string trimmer that does exactly what I needed:

    Please Login or Register  to view this content.
    It finds the first comma, deletes all the characters up to and including the comma, then finds the second comma and deletes everything after it. It also removed the comma. Thanks guys!

  7. #7
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Pulling a value from a string

    glad I could help....I do like the Split function also....great idea...

+ 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] Pulling a string of text
    By Montoro22 in forum Excel General
    Replies: 5
    Last Post: 06-11-2013, 11:36 AM
  2. [SOLVED] Pulling sections of a string
    By weeble33 in forum Excel General
    Replies: 5
    Last Post: 08-07-2012, 11:47 AM
  3. Pulling only the number out of a string
    By bconner in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-19-2008, 03:32 PM
  4. [SOLVED] Pulling apart a string
    By Kevin O'Neill in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-06-2006, 01:32 PM
  5. URL string, pulling in Stock Data
    By William Benson in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-15-2005, 01:05 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