+ Reply to Thread
Results 1 to 3 of 3

Help with Mid-Function and variable lengths.

Hybrid View

  1. #1
    Registered User
    Join Date
    05-31-2018
    Location
    Ottawa, Canada
    MS-Off Ver
    Office 2016
    Posts
    1

    Help with Mid-Function and variable lengths.

    Hi All,

    Looking to see if it is possible to use a mid/find function to find the string starting point and then pull the next characters up to a space, or multiple spaces. Essentially I'm trying to parse data pulled from an email, however the email is not always structured the same, yet I do have labels that will always appear before the words I want to pull (ex. Name: ....., Email: .... ). I copied below the formula I have been using when I have 2 known variables, however if I can figure out how to search variable 1, and then pull a word up to a space next to it that would fantastic.

    =MID(indirect("a"&row()),SEARCH("Variable1~:",indirect("a"&row()))+7,SEARCH("Variable2",indirect("a"&row()))-SEARCH("Variable1~:",indirect("a"&row()))-8)

    Thank you so much,

  2. #2
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,048

    Re: Help with Mid-Function and variable lengths.

    Hi, welcome to the forum

    To best describe or illustrate your problem you would be better off attaching a dummy workbook. The workbook should contain the same structure and some dummy data of the same type as the type you have in your real workbook - so, if a cell contains numbers & letters in this format abc-123 then that should be reflected in the dummy workbook.

    To attach a file to your post,
    click advanced (next to quick post),
    scroll down until you see "manage file",
    click that and select "add files" (top right corner).
    click "select files" find your file, click "open" click "upload" click 'done" bottom right. click "submit reply"

    Once the upload is completed the file name will appear below the input boxes in this window.
    You can then close the window to return to the new post screen.
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  3. #3
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Help with Mid-Function and variable lengths.

    This is a start

    =MIN(IF(ISERROR(FIND("Name",A1)),999,FIND("Name",A1)),IF(ISERROR(FIND("Surname",A1)),999,FIND("Surname",A1)),IF(ISERROR(FIND("Email",A1)),999,FIND("Email",A1)))

    It returns the position of the first occurrence of one of your search strings

    This finds the position of the first space after that point

    =FIND(" ",A1,MIN(IF(ISERROR(FIND("Name",A1)),999,FIND("Name",A1)),IF(ISERROR(FIND("Surname",A1)),999,FIND("Surname",A1)),IF(ISERROR(FIND("Email",A1)),999,FIND("Email",A1))))


    Put those togeather

    =MID(A1,MIN(IF(ISERROR(FIND("Name",A1)),999,FIND("Name",A1)),IF(ISERROR(FIND("Surname",A1)),999,FIND("Surname",A1)),IF(ISERROR(FIND("Email",A1)),999,FIND("Email",A1))),FIND(" ",A1,MIN(IF(ISERROR(FIND("Name",A1)),999,FIND("Name",A1)),IF(ISERROR(FIND("Surname",A1)),999,FIND("Surname",A1)),IF(ISERROR(FIND("Email",A1)),999,FIND("Email",A1))))-MIN(IF(ISERROR(FIND("Name",A1)),999,FIND("Name",A1)),IF(ISERROR(FIND("Surname",A1)),999,FIND("Surname",A1)),IF(ISERROR(FIND("Email",A1)),999,FIND("Email",A1))))

    Returns your text proceeded by your search string

    So you now need to get rid of your search string

    =SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(MID(A1,MIN(IF(ISERROR(FIND("Name",A1)),999,FIND("Name",A1)),IF(ISERROR(FIND("Surname",A1)),999,FIND("Surname",A1)),IF(ISERROR(FIND("Email",A1)),999,FIND("Email",A1))),FIND(" ",A1,MIN(IF(ISERROR(FIND("Name",A1)),999,FIND("Name",A1)),IF(ISERROR(FIND("Surname",A1)),999,FIND("Surname",A1)),IF(ISERROR(FIND("Email",A1)),999,FIND("Email",A1))))-MIN(IF(ISERROR(FIND("Name",A1)),999,FIND("Name",A1)),IF(ISERROR(FIND("Surname",A1)),999,FIND("Surname",A1)),IF(ISERROR(FIND("Email",A1)),999,FIND("Email",A1)))),"Name",""),"Surname",""),"Email","")

    Messy ha?

    I would use a userdefined function instead.
    Last edited by mehmetcik; 05-31-2018 at 04:06 PM.
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

+ 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 String After and Before Certain Characters of Variable Lengths
    By ex245 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 10-05-2017, 09:59 PM
  2. Adaptive forecasting based on variable project lengths
    By sjez27 in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 07-27-2017, 10:00 AM
  3. Determining shipping fees with variable lengths/weights
    By bakedziti in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-14-2017, 12:54 PM
  4. Variable VBA Array Lengths, insert into cell as string
    By Speshul in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-03-2014, 04:26 PM
  5. [SOLVED] Extract numbers of variable lengths from cell
    By Nizz in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 10-18-2013, 10:11 AM
  6. [SOLVED] Extracting Text From Cells of Variable Lengths
    By stinkstik in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 04-25-2013, 02:46 PM
  7. [SOLVED] Parsing data of variable lengths
    By JP Romano in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-02-2011, 04:54 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