Excel MID function - basic uses and advanced formula examples

MID is one of the Text functions that Microsoft Excel provides for manipulating text strings. At the most basic level, it is used to extract a substring from the middle of the text string. In this tutorial, we will discuss the syntax and specificities of the Excel MID function, and then you will learn a few creative uses to accomplish challenging tasks.

Excel MID function - syntax and basic uses

Generally speaking, the MID function in Excel is designed to pull a substring from the middle of the original text string. Technically speaking, the MID function returns the specified number of characters starting at the position you specify.

The Excel MID function has the following arguments:

MID(text, start_num, num_chars)


  • Text is the original text string.
  • Start_num is the position of the first character that you want to extract.
  • Num_chars is the number of characters to extract.

All 3 arguments are required.

For example, to pull 7 characters from the text string in A2, starting with the 8th character, use this formula:

=MID(A2,8, 7)

The result might look something similar to this:

Using the MID function in Excel

5 things you should know about Excel MID function

As you have just seen, there's no rocket science in using the MID function in Excel. And remembering the following simple facts will keep you safe from most common errors.

  1. The MID function always returns a text string, even if the extracted substring contains only digits. This may be critical if you wish to use the result of your Mid formula within other calculations. To convert an output into a number, use MID in combination with the VALUE function as shown in this example.
  2. If start_num is greater than the overall length of the original text, an Excel Mid formula returns an empty string ("").
  1. If start_num is less than 1, a Mid formula returns the #VALUE! error.
  2. If num_chars is less than 0 (negative number), a Mid formula returns the #VALUE! error. If num_chars is equal to 0, it outputs an empty string (blank cell).
  3. If the sum of start_num and num_chars exceeds the total length of the original string, the Excel MID function returns a substring starting from start_num and up to the last character.

Excel MID function - formula examples

When dealing with real-life tasks in Excel, you will most often need to use MID in combination with other functions as demonstrated in the following examples.

How to extract first and last name

If you've had a chance to read our recent tutorials, you already know how to pull the first name using the LEFT function and get the last name with the RIGHT function. But as is often the case in Excel, the same thing can be done in a variety of ways.

MID formula to get the first name

Assuming the full name is in cell A2, first and last names separated with a space character, you can pull the first name using this formula:

=MID(A2,1,SEARCH(" ",A2)-1)

The SEARCH function is used to scan the original string for the space character (" ") and return its position, from which you subtract 1 to avoid trailing spaces. And then, you use the MID function to return a substring beginning with the fist character and up to the character preceding the space, thus fetching the first name.

MID formula to get the last name

To extract the last name from A2, use this formula:


Again, you use the SEARCH function to determine the starting position (a space). There is no need for us to calculate the end position exactly (as you remember, if start_num and num_chars combined is bigger than the total string length, all remaining characters are returned). So, in the num_chars argument, you simply supply the total length of the original string returned by the LEN function. Instead of LEN, you can put a number that represents the longest surname you expect to find, for example 100. Finally, the TRIM function removes extra spaces, and you get the following result:
Excel MID formulas to extract the first and last names

How to get substring between 2 delimiters

Taking the previous example further, if besides first and last names cell A2 also contains a middle name, how do you extract it?

Technically, the task boils down to working out the positions of two spaces in the original string, and you can have it done in this way:

  • Like in the previous example, use the SEARCH function to determine the position of the first space (" "), to which you add 1 because you want to start with the character that follows the space. Thus, you get the start_num argument of your Mid formula: SEARCH(" ",A2)+1
  • Next, get the position of the 2nd space character by using nested Search functions that instruct Excel to start searching from the 2nd occurrence of the space character: SEARCH(" ",A2,SEARCH(" ",A2)+1)

    To find out the number of characters to return, subtract the position of the 1st space from the position of the 2nd space, and then subtract 1 from the result since you don't want any extra spaces in the resulting substring. Thus, you have the num_chars argument: SEARCH (" ", A2, SEARCH (" ",A2)+1) - SEARCH (" ",A2)

With all the arguments put together, here comes the Excel Mid formula to extract a substring between 2 space characters:

=MID(A2, SEARCH(" ",A2)+1, SEARCH (" ", A2, SEARCH (" ",A2)+1) - SEARCH (" ",A2)-1)

The following screenshot shows the result:
Mid formula to get substring between 2 spaces

In a similar manner, you can extract a substring between any other delimiters:

MID(string, SEARCH(delimiter, string)+1, SEARCH (delimiter, string, SEARCH (delimiter, string)+1) - SEARCH (delimiter, string)-1)

For example, to pull a substring that is separated by a comma and a space, use this formula:

=MID(A2,SEARCH(", ",A2)+1,SEARCH(", ",A2,SEARCH(", ",A2)+1)-SEARCH(", ",A2)-1)

In the following screenshot, this formula is used to extract the state, and it does the job perfectly:

Mid formula to extract a substring separated by a comma and a space.

How to extract Nth word from a text string

This example demonstrates an inventive use of a complex Mid formula in Excel, which includes 5 different functions:

  • LEN - to get the total string length.
  • REPT - repeat a specific character a given number of times.
  • SUBSTITUTE - replace one character with another.
  • MID - extract a substring.
  • TRIM - remove extra spaces.

The generic formula is as follows:

TRIM(MID(SUBSTITUTE(string," ",REPT(" ",LEN(string))), (N-1)*LEN(string)+1, LEN(string)))


  • String is the original text string from which you want to extract the desired word.
  • N is the number of word to be extracted.

For instance, to pull the 2nd word from the string in A2, use this formula:

=TRIM(MID(SUBSTITUTE(A2," ",REPT(" ",LEN(A2))), (2-1)*LEN(A2)+1, LEN(A2)))

Or, you can input the number of the word to extract (N) in some cell and reference that cell in your formula, like shown in the screenshot below:

Excel Mid formula to extract Nth word from a text string

How this formula works

In essence, the formula wraps each word in the original string with many spaces, finds the desired "spaces-word-spaces" block, extracts it, and then removes extra spaces. To be more specific, the formula works with the following logic:

  • The SUBSTITUTE and REPT functions replace each space in the string with multiple spaces. The number of additional spaces is equal to the total length of the original string returned by LEN: SUBSTITUTE(A2," ",REPT(" ",LEN(A2)))

    You can think of an intermediate result as of "asteroids" of words drifting in space, like this: spaces-word1-spaces-word2-spaces-word3-… This "spacious" string is supplied to the text argument of our Mid formula.

  • Next, you work out the starting position of the substring of interest (start_num argument) using the following equation: (N-1)*LEN(A1)+1. This calculation returns either the position of the first character of the desired word or, more often, the position of some space character in the preceding space separation.
  • The number of characters to extract (num_chars argument) is the easiest part - you simply take the overall length of the original string: LEN(A2). At this point, you are left with spaces-desired word-spaces substring.
  • Finally, the TRIM function gets rid of leading and trailing spaces.

The above formula works fine in most situations. However, if there happen to be 2 or more consecutive spaces between words, it yields wrong results. To fix this, nest another TRIM function inside SUBSTITUTE to remove excess in-between spaces except for a single space character between words, like this:

=TRIM(MID(SUBSTITUTE(TRIM(A2)," ",REPT(" ",LEN(A2))), (B2-1)*LEN(A2)+1, LEN(A2)))

The following screenshot demonstrates the improved formula in action:
An improved Mid formula to extract Nth word from text string

If your source strings contain multiple spaces between words as well as very big and very small words, additionally embed a TRIM function into each LEN, just to keep you on the safe side:


I agree that this formula looks a bit cumbersome, but it impeccably handles all kinds of strings.

How to extract a word containing a specific character(s)

This example shows another non-trivial Excel Mid formula that pulls a word containing a specific character(s) from anywhere in the original text string:

TRIM(MID(SUBSTITUTE(string," ",REPT(" ",99)),MAX(1,FIND(char,SUBSTITUTE(string," ",REPT(" ",99)))-50),99))

Assuming the original text is in cell A2, and you are looking to get a substring containing the "$" character (the price), the formula takes the following shape:

=TRIM(MID(SUBSTITUTE(A2," ",REPT(" ",99)),MAX(1,FIND("$",SUBSTITUTE(A2," ",REPT(" ",99)))-50),99))

Mid formula to extract a word containing a specific character

In a similar fashion, you can extract email addresses (based on the "@" char), web-site names (based on "www"), and so on.

How this formula works

Like in the previous example, the SUBSTITUTE and REPT functions turn every single space in the original text string into multiple spaces, more precisely, 99 spaces.

The FIND function locates the position of the desired character ($ in this example), from which you subtract 50. This takes you 50 characters back and puts somewhere in the middle of the 99-spaces block that precedes the substring containing the specified character.

The MAX function is used to handle the situation when the desired substring appears in the beginning of the original text string. In this case, the result of FIND()-50 will be a negative number, and MAX(1, FIND()-50) replaces it with 1.

From that starting point, the MID function collects the next 99 characters and returns the substring of interest surrounded by lots of spaces, like this: spaces-substring-spaces. As usual, the TRIM function helps you eliminate extra spaces.

Tip. If the substring to be extracted is very big, replace 99 and 50 with bigger numbers, say 1000 and 500.

How to force an Excel Mid formula to return a number

Like other Text functions, Excel MID always returns a text string, even if it contains only digits and looks much like a number. To turn the output into a number, simply "warp" your Mid formula into the VALUE function that converts a text value representing a number to a number.

For example, to extract a 3-char substring beginning with the 7th character and convert it to a number, use this formula:


The screenshot below demonstrates the result. Please notice the right-aligned numbers pulled into column B, as opposed to the original left-aligning text strings in column A:

Use the Excel MID function together with VALUE to return a number

The same approach works for more complex formulas as well. In the above example, assuming the error codes are of a variable length, you can extract them using the Mid formula that gets a substring between 2 delimiters, nested within the VALUE function:


Nest a Mid formula in the VALUE function to turn the output into a number.

This is how you use the MID function in Excel. To better understand the formulas discussed in this tutorial, you are welcome to download a sample Excel MID function workbook. For more Mid formula examples, be sure to check out the following resources. I thank you for reading and hope to see you on our blog next week!

More examples of using the MID function in Excel:

143 responses to "Excel MID function - basic uses and advanced formula examples"

  1. Rohan Singh says:

    wOW Svetlana!!!! Very Nice Article.

  2. Chuck Allen says:

    Great article. Find your sight so helpful.
    I'm trying to pull specific digits from a string - WC5-39S-311704-022
    I need 6th, 8th & 9-14th, so 9-311704.
    Trying for a few days to figure this out.
    Any help is appreciated.

  3. Shashie says:

    Hi Svetlana.
    I have a column for dates and I want to count how many dates are there? if there are more than one date in a single cell, separated by a comma
    (eg.in cell A2=08/02/17,09/02/17,10/02/17). it should come 3.how can i count it using 'countif'formula?
    I tried
    =countif (a2:a10,"*"&",")
    but it doesn't work.
    can u help me on this?

  4. Java_uz says:


  5. mohamad says:

    thanks a lot.very very good

  6. Netrapal Yadav says:

    Awesome thanks a lot..very helpful article.

  7. Jensen says:


    So I have used the MID function for various financial data, but when the data has 1 or 2 zeros as the first decimals, it gives faulty readings (4..2 and "VALUE!" respectively). I assume this has something to do with "NUM_CHARS" and the fact that excel does not recognize a zero at the end. When I use this function: "=MID(40.20,1,LEN(40.20)-3)&"."&MID(40.20,LEN(40.20)-1,2)&"%"" it gives "4..2" rather than "40.20%".

    I tried to change the "40.20" to custom rather than "number" but it wouldn't stick. When I went back into format cells, it was back on "number".

    If there is a brilliant geek somewhere out there, I would appreciate it sooo much

  8. Siddharth says:


    Please advise me.

    As shown below,i want to divide only period in excel sheet.
    is it possible or not, If it is possible could you please let me know.

    AKASH ALLAMUNENI 05/01/17-05/31/17 176 HRS 73

  9. Chris Levay says:

    Hi Svetlana!
    Nice info! I have a question. I try to extract some characters from a cell twice. Let me explain:
    I have some words I need to eliminate from the original cell. Example:
    "My Dog is a beatiful black animal" to become "My Dog is a black animal".
    Is there a way to apply the MID function twice in the same cell who let me extract "My Dog is a" and then "black animal"? And if is not possible... Is there a way to do?
    Thanks a lot!!!

  10. Shelia LeBeauf says:

    Hi Svetlana,
    This is exactly what I looking for. In the TRIM formula where a dollar amount was extracted, I replaced the "$" with two characters "V-" and no matter the length of the work (ie: V-1234 or V-1234A), the correct information was extracted. How would you build this in an IF function where the characters being searched vary. Example: T-1234, P-1234, V-1234, C-1234, D-1234, E-1234; IF "T-", IF "P-", IF "V-", so forth.
    Thank you for the formula, I just need to build on it. Any help would be greatly appreciated.

  11. Sindre Langberg says:

    Hi! Thank you for this very informative article.

    Still i have some problems I wonder if you can help me out with

    I have this string and many other similar to this:
    "1000Miglia 047 7,5x17 5-108 ET45 CB63,4"
    And I want to extract the numbers infront of "x" from the second " ".
    That means in this text i want to extract the number "7,5"

    Is there any simple formula for that?

  12. aina says:

    I am trying to use the Mid/Find function on this problem but I can't seem to get it correctly.

    SNACKNATION 310-845-7744 CA
    EGENFEE* 866-397-2677 WA
    KROGER #710 00000071 HARPER WOODS MI

    I need to separate these on each column but I'm always getting the #VALUE :(

    can someone please help me?

  13. binod says:

    please help me.
    want to extract text and numbers from one cell to different rows with function.
    each of the following line should be extracted to different rows.
    following is in only one cell.

    • Hello,

      If I understand your task correctly, please try the following formulas:

      1. To extract text:

      2. To extract numbers:

      Hope this will help you with your task.

  14. Alfredo says:

    Thank you Svetlana for the great article! It's awesome!

    I would really appreciate some help, I have been going crazy trying to find the solution. Could someone please help me with a formula to extract the name, Barack Obama from the string below?

    [{"account_id":555,"name":"Barack Obama "}]

    Thank you very much!

    • Troy Buschbom says:

      My answer:

      I placed your code in cell C4 then added:
      =IF(ISNUMBER(SEARCH(E4,C4)),"Found - "&E4,"* No Match *")

      to cell D4 and in cell E4 I added the text "Barack Obama"

      The formula will look in cell C4 for whatever text you have in cell E4 and if it is found, the cell D4 will reflect what was searched or it will return
      * No Match *
      A nice feature of SEARCH is that it is not case sensitive.

  15. Ahmed says:

    What If I Have Like A $ Sign Followed By Space Then The Number I Want ? Can U Help Me ?

  16. Kasun Tharanga says:

    This is beyond from the subject.
    I wants to know how to include (value) for each records which are indicating with minus figures. Eg -50 = (50).

  17. Ratu Yufina says:


    Please advise me.

    As shown below,i want to divide only regional name (mark in ===) in excel sheet.
    is it possible or not, If it is possible could you please let me know.


    Thank You

  18. Debbie says:

    I have a worksheet with text in column A. I need to find the 2nd time a phrase occurs and extract the number from the right of the common word.
    I can extract the entire line, but need the 2 characters from the second occurrence. Can't figure out how to do this.

  19. Guna says:

    PO=65777570000 ASN=7266271

    I need to extract the mid value of the above line that is "65777570000"

    • Doug says:

      A formula to extract 65777570000 uses the MID function.
      Using your sample where it is in K6 the formula is:
      =MID(K6,4,11) It says, "In K6 go four characters from the left and extract the next 11 characters."

  20. Robyn says:

    I created a Mid formula to pull out a letter of a number sequence, so I could determine an agency (18N12345 = mid formula pulls out the "N"). However, when I have 18F12345, the F turns red, and the cell color turns pink. The first few times I did it, it crashed excel. Any idea why the "F" has that effect? I have no conditional formats created for these cells.

  21. Jasmin U says:

    Very useful at work! Thank you very much for making this article. Much appreciated!

  22. Chris says:

    Hi Anna,

    I'm trying to use MID within a SUMPRODUCTS function, but I want to compare the result to a number value, not a string. I tried wrapping the MID array in a VALUE function, but it returns an error. Do you know if there's any way around this?

    Essentially my code looks like this:


  23. Kata says:

    Hi, I have this formula: =MID(F3;FIND("09";F3;1);14)

    to exract phone number from text string, but it shows #VALUE! when there is no number in the string. I htere a way to insert this funtion into some other to get just an empty cell?

    I'm no excel expert so any help is welcome.


  24. Kata says:

    I tryed different things, gor to that function to and it worked until I came across a cell with 6 digit nummer starting with 3XX XXX. I wish I could find VBA code like the one for the extracting e-mail from string, it saved me days of work, unlike this phone number problem.

    Function ExtractEmailFun(extractStr As String) As String
    'Update 20130829
    Dim CharList As String
    On Error Resume Next
    CheckStr = "[A-Za-z0-9._-]"
    OutStr = ""
    Index = 1
    Do While True
    Index1 = VBA.InStr(Index, extractStr, "@")
    getStr = ""
    If Index1 > 0 Then
    For p = Index1 - 1 To 1 Step -1
    If Mid(extractStr, p, 1) Like CheckStr Then
    getStr = Mid(extractStr, p, 1) & getStr
    Exit For
    End If
    getStr = getStr & "@"
    For p = Index1 + 1 To Len(extractStr)
    If Mid(extractStr, p, 1) Like CheckStr Then
    getStr = getStr & Mid(extractStr, p, 1)
    Exit For
    End If
    Index = Index1 + 1
    If OutStr = "" Then
    OutStr = getStr
    OutStr = OutStr & Chr(10) & getStr
    End If
    Exit Do
    End If
    ExtractEmailFun = OutStr
    End Function

  25. Kata says:

    So I've downloaded your add in for excel, text toolkit, did what i had to do and was done in half an hour.

    Thank you! One qestion, is this add in in excel 365 online free?

  26. Swathi says:

    how to extract only the number say suppose there are 100 of rows.. in one row it will be abcd - 2571818 & in second row abcd (173897).
    please help

  27. RAVI says:

    HI I AM RAVI ,

    • Ragavendran says:

      Dear Mr Ravi
      Please use this formula to find the 5 charecter in specified cell.

      Note : A1 is the example cell reference for your requirement.

  28. Lavish Angel G says:

    Hi there, I need help.
    Lets say I have a series starting with A until V
    Lets say I have a sequence that reads "ABCDEFGHIJK", now I need something that can say TRUE when my series contains more than 7 letters from the group A to K, and false when my series contains less than 7 letters from the group A to K.

    For example.

    Any help would be greatly appreciated. :)

  29. Gregory Williams says:

    I am looking to rearrange a date using Left, Mid and Right; unless someone has a better way to do this. Mt date is for example 20190101 ... I want to reformat the call to look like 01/01/2019. I am trying =RIGHT(A1,2),MID(A1,4,2),LEFT(A1,4)

    • Gregory Williams says:

      I don't know how to delete my comment but as I was about to give up I figured it out!
      20190101 changes to 01/01/2019

  30. Charlie says:

    Hi, Fantastic Article!
    Is there any way to search for additional data within the same cell and have all the data that is pulled out, separated by a comma?
    I have a cell with 1 to 5 user names and ID's. The ID's are in parenthesis and I want to pull the ID's out to be separated by a comma.
    My worksheet is setup like the data below in a single column, but with 240 rows.
    Smith,Jim A (123456)Doe,John (789123)
    Boss,Tim (293029)Deer,Fred(001289)Stern,Greg(148900)
    I'm trying to get the data to return like this:

  31. Leandra says:

    trying to get it to use an IF function along with a MID in extracting numbers withing a string of both text and numbers.

    PBQ4X5 - using =MID(A2, SEARCH("Q",A2)+1, 1) to return the "4" and the same with "X" to return the number associated with it. Unfortunately when it runs across a sequence that doesn't include either the X or the Q (PBI5G3), I get "#VALUE!". I also get "#VALUE when trying to "sum" the number columns that the formula returns. Trying to come up with an IF formula to incorporate with the MID and SEARCH so that it will return a "0" when it can't find the particular text (Q or X). Any help would be appreciated, I've been working on this for quite a while.

  32. SOLOMON says:

    HI, I used this formula =TRIM(MID(SUBSTITUTE(E4991," ",REPT(" ",99)),MAX(1,FIND("IL",SUBSTITUTE(E4991," ",REPT(" ",99)))-50),99)), which worked well with my case 2 and 3 below but did not give the desired result for case 1 and 4 due to the fact that there are no space in the case 1.
    Result i need is 16 characters starting with IL included.
    Case 1 : MF20020011111IL11000NG0000001
    case 2 : MF20020022222 IL11000NG0000002 revalued
    case 3 : IL11000NG0000002 MF20020022222 revalued
    Case 4 : MF20020033333IL11000NG0000003revalued

  33. Munther says:

    Can i make mid function start from the right direction and select the number on the left side of the spesfic number with out use right function ?

  34. Naneida says:

    I am using the following to extract "ES" text from a cell. How can I edit the formula to extract additional text, i.e. "ES", "MS", and "HS"? Thanks a lot in advance!
    =TRIM(MID(SUBSTITUTE(F19," ",REPT(" ",99)),MAX(1,FIND("ES",SUBSTITUTE(F19," ",REPT(" ",99)))-50),99))

  35. pradosh says:

    i want to "HSBC - Any domestic business banking relationships - Please now think about your personal banking relationships and the business' domestic banking relationships in Australia" this text as "Please now think about your personal banking relationships and the business' domestic banking relationships in Australia - Any domestic business banking relationships - HSBC", please help me how i can do this.

  36. Lan says:

    Hi I have a query, i have to search multiple 8-10 Character strings from one cell example A1 like SAM1, SAM2, SAM3, SAM4, ZOP1, ZOP2, ADS1, ADS2.... and need to update the matching value example B2 SAM12345. Kindly advise me how could this be achieved. I have used the below formula but it has not worked, kindly provide your assistance....

  37. Kelly says:

    Great article!
    I'm trying to do a complex string and struggling to get the final output:
    Formula Output= \AI01653_-W (close - but I don't want the \ in the result.

    Using your example with a -1 at the end, doesn't work either:
    Formula Output= \AI01653_-W_DER8Z (not close, do not want anything from the second underscore on in the result.

  38. Efren says:

    =IF(MID(J2,2,1)="O","OO","RT") --- i have this formula correctly.

    However, i need to add another criteria MID(J2,3,1)="O"
    Please help.

    Thank you!

  39. Joanna says:

    I have a rather complex formula and one portion of it is not working. Basically, one cell (C17) Has wording that shows how many boxes in a bundle there is. However, this item has 2 parts to the box. The cell says "375 TOP450 BOTTOM" which represents that the top portion of the box comes 375 in a bundle and the bottom portion comes 450 in a bundle. It uses the Char(10) function to place it in 2 lines within the same box. In another box (B17) is the amount of cases that are needed for a run. What I need to return in a separate box is a calculation of how many bundles are needed for the top and bottom rounded up to the nearest number. Essentially, if we need 1875 cases total it should return "5 TOP 5 BOTTOM". The first half of the formula works fine. The second half is not recognizing the extracted number as a number which is making it return a VALUE# error. I tried to wrap the function as a number but that still down't work.
    Here is the part of the formula that works and returns 450 as expected:
    It is when I try to divide the total cases needed by that number extracted extracted that I get the error.
    1875/(MID(C17,SEARCH("P",C17)+2,ABS((SEARCH("P",C17,SEARCH("P",C17)-1)-SEARCH("B",C17)+2)))) should return 4.16
    If I add the Value function like below, I get a value error.
    How can I get the mid function depicted to recognize the return as a number?

    To be clear, the first portion of my formula worked. So I was able to extract the 375 and divide 1875 by 375 and return the expected value as 5. It's only this second half I am having trouble with. Can anyone please help?

  40. Gregg says:

    I am using the MID function to concatenate three columns. Similar to this formula
    The formula works, but there is a space between the concatenations. How do i remove these spaces?

  41. Kishan Sharma says:

    Apple iPhone 6 Space Grey 16 GB RAM ROM
    Model Name
    Alag kesa kr sakte h

  42. vivek khare says:

    this function =REPT("0",4-LEN(A1))&A1 use for Len sent
    But how to use for 1 to extend 1000.

    • Hello Vivek!
      If you want to add 0 at the end of the value in cell A1, please use this formula:
      =A1 & REPT("0",4-LEN(A1))
      If you want to increase the length of a string, please change number “4” in the formula to the necessary number, e.g. 5,6,7, etc.
      If you mean something different, then please describe your problem in more detail.

  43. Vince says:

    I have data set with US and Canadian addresses in one column. I tried using the text to columns functions in order to break everything, but it's inconsistent. Is there any way of using these formulas to pull out the US states and Canadian territories?

  44. Hello Vince!
    For me to be able to help you better, please describe your task in more detail. It’ll help me understand it better and find a solution for you. Thank you.

  45. Reinette says:

    Thank you in advance for helping me with formula.
    I need to get the middle section of the id number and if the number is smaller than 4999 it should show F for Female if it is bigger than 5000 it should show M for Male. I am using the following formula but I am doing something wrong. The ID number is 5711261588092 and the middle part is 1588 so it should return F.

    • Hello Reinette!
      The formula below will do the trick for you:


      The MID function returns the text that you are comparing with a number. Therefore, you get the wrong result. I have converted your text to a number.
      I hope this will help, otherwise please do not hesitate to contact me anytime.

  46. Ryan says:

    Je voudrai un algorithme avec la fonction mid qui peut calculer le nombre de mots d'un document entier s'il vous plaît

  47. Liew says:

    Hi, Fantastic Article!
    I love this formula.
    =TRIM(MID(SUBSTITUTE(A2," ",REPT(" ",99)),MAX(1,FIND("$",SUBSTITUTE(A2," ",REPT(" ",99)))-50),99))
    I got a question, how to change to formula if we want to extract more than 2 $ in A2
    Thanks in advance.
    Brilliant Formula.

    • Hello!
      If I understand your task correctly, you would like to extract the second number from the text that starts with the $ sign. If so,
      from text
      "This item costs $50 and you get a discount of $15"
      we extract "$15".

      =TRIM(MID(SUBSTITUTE(REPLACE(A2,FIND("$",A2,1),1,"")," ",REPT(" ",99)), MAX(1,FIND("$",SUBSTITUTE(REPLACE(A2,FIND("$",A2,1),1,"")," ",REPT(" ",99)))-50),99))

      Hope this is what you need.

      • Liew says:

        Thanks for your quick reply. Brilliant!!
        "This item costs $50 and you get a discount of $15"
        Actually, I would like to extract the $50 and $15, both of them. And also if possible to extract the word of $ 15 (there is space between the $ and 15 or any word ($ xx) (xx=number))

        Thanks in advance.

      • Fawwaz says:

        What if we want to extract up to 5 set of number in a text? For example $50, &23, $45, $56 and %60.

  48. Jaiantha says:

    How can I get the only "PRV";"PI"& "F" by using one formula from the data?

  49. Deepak Altia says:


    I have one excel like this value 0+11+21+32+45+112+37,
    i want to split using formula to like 0,11,21,32,45,112,37 in different cells.
    I found first 2 values,
    =LEFT(A3,SEARCH("+",A3,1)-1) (First number)
    =MID(A3, SEARCH("+",A3) + 1, SEARCH("+",A3,SEARCH("+",A3)+1) - SEARCH("+",A3) - 1) (second number)
    but I am unable to get next number onwards.

    Could you help me

  50. Cate says:

    Is there a way to use a mid function if you do not know the location of the number you are looking to pull?
    For example, I am uploading email confirmations for an excel file. I need to pull out the order number from the subject column for each line. However, I do know the numbers I am looking for are 7 digits long and begin with a 9. Is there a way to use a mid function to pull a number if it meets that criteria?

  51. Vinod Kumar says:

    could someone help to get the output only with the date. There are 2 different dates in one column..
    Generate on Begin time :Sun Jul 5 0:0:0 2020
    GenerateOn Begin time : Sun May 10 05:36:52 2020
    I would require the output as MM/DD/YYYY Only from both the fields..
    Thanks in Advance..

    • Hello!
      If I got you right, the formula below will help you with your task:

      =DATE(RIGHT(A1,4),VLOOKUP(MID(A1,5,3), {"JAN",1;"FEB",2;"MAR",3;"APR",4;"May",5;"JUN",6;"JUL",7;"AUG",8;"SEP",9;"OCT",10;"NOV",11;"DEC",12}, 2,0), MID(A1,FIND("#",SUBSTITUTE(A1," ","#",2))+1, FIND("#",SUBSTITUTE(A1," ","#",3))-FIND("#",SUBSTITUTE(A1," ","#",2))-1))

      Custom date format in the cell set as you need.

      • vinod kumar says:

        Good Morning Alex !
        actually both the mentioned format is different and having text as well.. I have pasted example below. from below 2 columns I need to extract the date in respect to any date format (like dd/mm/yyyy) or (MM/DD/YYYY) but that should be standard.. would appreciated to help me in this regards Sir.. Thanks in Advance..

        Generate on Begin time :Sun Jul 5 0:0:0 2020
        GenerateOn Begin time : Sun May 10 05:36:52 2020

  52. Worker says:

    How can i extract the first number on these data.

    ThePLAN PLUS 1299 (Value 1899)
    ThePLAN 1799
    ThePLAN PLUS 1299 (Value 1899)

  53. Chethan says:

    (Backlash X @ -3.5 @ 4.0mm) If I want extract the value between @ and @ in the next cell @ and mm how to apply the mid and find function...

  54. Suanson says:

    Hello guys, can someone help with getting the first value on a text.
    So i want to get the 1st numbers on this text:
    ABCDEFG 1234 (ABCD 1920) I want to get the 1234
    BCBAKHJFAKFAHKLJS 1237214 (BABY-HKLJ) I want to get the 1237

    Please need help, thank you.

    • Hello!
      To extract the first 4 digits from the text, you can use this formula


      Hope this is what you need.

      • Suason says:

        It works like charm! Thank you so much Alex!

      • Suanson says:

        I'm working on a large amount of data. What i want is to determine if the old plan versus the new plan is a "Upgrade", "Downgrade" or "Retain".

        Sample: Old Plan vs New Plan
        Family Plan 1299 vs FamCombo 1699 result "Upgrade"
        ValuePack 599 (Data 299) vs Family Plan 1999 (All in 1299) result "Upgrade"
        So the bases plan is the 1st number. How can i construct the IF statement on this one? Need your help!

        Thank you so much!

        • Hello Suanson!
          I’m sorry but your task is not entirely clear to me. Could you please describe it in more detail?
          Please explain in more detail what conditions are "Upgrade", "Downgrade" or "Retain"?
          Why "Family Plan 1299 vs FamCombo 1699 result" Upgrade "? Under what condition will the result be "Downgrade" or "Retain"?
          Is this entry in one cell or in several?

          • Suanson says:

            It's like this...
            If B is greater than A then it will display "Upgrade"
            If B is less than A then it's a "Downgrade"
            IF B is equal to A then the plan has been retained "Retain"
            (B is the old plan while A is the new plan)

            • Hello!
              You haven't answered all my questions. I don't want to waste time guessing. I ask again. "Family Plan 1299 vs FamCombo 1699" - written in one cell or in several? Are the numbers 1299 and 1699 being compared? If you want help, please describe in detail your problem.

              • Suanson says:

                It's written in different cell.
                Column A Family Plan 1299
                Colum B FamCombo 1699

                and yes, the numbers are being compared. Sorry i have a very limited time in the office, and can only access it here.

  55. David says:

    I am trying to extract the last characters in a string. However the string is not always the same length nor the number of characters I need to extract, example:
    I need the characters at the end of the string after the numbers. Any help would be great.

  56. Moheen says:

    How to search three values using mid function i.e. use of "OR" statement in mid formula so we can able to search specific value thats meets two criteria (i have a lot of excel rows containing data in which sonme of them have personal information of persons and some of them are containing word "Vacant" so i would try to extract data of all cell and result shown personal data of persons and as well as word "vacant" shown if the cell containing data "Vacant". please help me!!!

  57. Hairul Alam says:

    I have a problem like this, the more number of letters I will separate, for example G: \ DCC \ EPC \ PIPELINE \ MRPR \ FINAL DOCUMENTATION
    I want to separate 1 (G), 2 (DCC), 3 (EPC), 4 (PIPELINE), 5 (MRPR), 6 (FINAL DOCUMENTATION) please find a solution, Thank you very much

  58. Pascal says:

    I would need some help on following extraction:
    I need to extract the sender person of a bank transaction. So, I need to extract the words between the IBAN (which always starts with CH* and always has 21 digits) and between the word SENDER. IBAN is variable and count of extracted words as well (2,3 or 4 depending on sender reference name).
    Example of my cell:
    GIRO BANK CH9909990456345323499 Tester Max Noah Bern SENDER REFERENCE
    Extraction should be "Tester Max Noah Bern"
    Thanks a lot!

    • Hello!
      If I understand your task correctly, the following formula should work for you:


      We have a tool that can solve your task in a couple of clicks: Ablebits Data - Split Text.

      This tool is available as a part of our Ultimate Suite for Excel that you can install in a trial mode and use for free: https://www.ablebits.com/files/get.php?addin=xl-suite&f=free-trial

      • Pascal says:

        Thanks for your quick answer!
        Unfortunately this does not work, because we have 2 problems:
        - leading words can be different in count and variation (can have 4,6,7.. words)
        - and leading words can include "CH" as well
        e.g. another row looks like this:
        GIRO BANK RAIFFEISEN SCHWEIZ GENOSSENSCHAFT DORFSTRASSE 99 999999 ALIGDNSLIW CH9812349000003109099 Beatrice Tester Bernstrasse 99 1234 Bern SENDER
        From here I would have to extract "Selina"" ""Howald"" "Bern".
        So I always have to extract the 2 words after the IBAN (right from CH*) and 1 word left from "SENDER". Count of words at beginning can differ as written above.
        Thanks again for your help!

  59. Rose says:

    I have an excel with transaction downloads from my bank. One column has the entries for the vendor of teh transaction but all are long and can differ. I want to extract one word (the vendor name) and place it in the next column in that row.

    So, let's say that the cell D48 has a long string such as:
    I want to find one word AMAZON and place that in cell E48.

    I will use the formula you provide to do this function for all my vendors, like PGE, AT&T, "Fred Meyer"

  60. Laksand says:


    I use the following formula =-LOOKUP(1,-LEFT(MID(A1,MIN(SEARCH({0,1,2,3,4,5,6,7,8,9},A1&"0123456789")),LEN(A1)-MIN(SEARCH({0,1,2,3,4,5,6,7,8,9},A1&"0123456789"))+1),ROW(INDIRECT("1:"&LEN(MID(A1,MIN(SEARCH({0,1,2,3,4,5,6,7,8,9},A1&"0123456789")),LEN(A1)-MIN(SEARCH({0,1,2,3,4,5,6,7,8,9},A1&"0123456789"))+1))))))

    This gives me the first set of digits (202009260630) in the string below, however I need to change this around so it gives me the last set of digits between underscore and .zip, in this case (1). I hope its just some minor adjustments to the provided formula that is needed.

    If anyone is thinking of more smooth solutions I can add that the amount of underscores varies, and that the amount of digits between last underscore and.zip also varies. IE string length varies


    • Hello!
      Please describe your problem in more detail. Include an example of the source data and the result you want to get. It’ll help me understand your request better and find a solution for you.

      • Laksand says:

        So Sourcedata look like this;

        The formula i provided in the first post provides me with the following set of digits from each row;

        Now, what I wan't it to do is to provide me with the last set of digits in each string;

        Let me know if you need me to elaborate further :)

        • Hello!
          The question of how to extract all the numbers from the text has been asked many times. Here is one of the answers.

          • Laksand says:

            Hello Alexander,

            I will elaborate further. Regarding the link you sent me, none of the examples include a string with 2 different set of digits(numbers in them). I'm not interested in extracting all numbers. I am interested in extracting the last set of numbers that in this case is between the last _ and .zip

            The link also mentions using positions, but position varies as the filename lenght varies.

            The reason why I provided this formula: =-LOOKUP(1,-LEFT(MID(A1,MIN(SEARCH({0,1,2,3,4,5,6,7,8,9},A1&"0123456789")),LEN(A1)-MIN(SEARCH({0,1,2,3,4,5,6,7,8,9},A1&"0123456789"))+1),ROW(INDIRECT("1:"&LEN(MID(A1,MIN(SEARCH({0,1,2,3,4,5,6,7,8,9},A1&"0123456789")),LEN(A1)-MIN(SEARCH({0,1,2,3,4,5,6,7,8,9},A1&"0123456789"))+1))))))

            Is because the way I understand it is that it searches from the left til it hits the first digit(number) and continues until it hits a non number Thus providing me with the whole numberseriers of only the first continous numberseries.

            I'm no expert in this but I thought maybe one of the experts here knew how the formula i provided could be tweaked to do exactly the same, but start from the right, so I get the last continuous numberseries of the source data.

            In other words I want the formula to return 21 from the following source data; gateway_files_202009250630_21.zip

            • Hello!
              Here is the formula that should work perfectly for you:

              =MID(SUBSTITUTE(A2,"_","@",LEN(A2)-LEN(SUBSTITUTE(A2,"_",""))), FIND("@",SUBSTITUTE(A2,"_","@",LEN(A2)-LEN(SUBSTITUTE(A2,"_",""))))+1, SEARCH(".",C8,1)-SEARCH("@*.",C8,1)-1)

              Hope this is what you need.

              • Laksand says:

                Hello Alexander,

                Sorry for a late reply,
                Im not an expert in this, but it seems like you refer to something in cell C8, It's not obvious to me what this is. I assume the filename is located in A2.

                Are you able to provide a picture of the extracted result from the file with the sourcedata where the formula is applied? :)

              • Hello,
                I am sorry for the inaccuracy. Here is the complete formula

                =MID(SUBSTITUTE(A2,"_","@",LEN(A2)-LEN(SUBSTITUTE(A2,"_",""))), FIND("@",SUBSTITUTE(A2,"_","@",LEN(A2)-LEN(SUBSTITUTE(A2,"_",""))))+1, SEARCH(".",SUBSTITUTE(A2,"_","@",LEN(A2)-LEN(SUBSTITUTE(A2,"_",""))),1) -SEARCH("@*.",SUBSTITUTE(A2,"_","@",LEN(A2)- LEN(SUBSTITUTE(A2,"_",""))),1)-1)

  61. Laksand says:

    Awsome work Alexander. Works perfectly!

  62. Pal says:


    How do I extract the LAST word from the cell that contains any of the specific characters?

    1. FirstName LastName 7.8 2
    2. FirstName LastName 7.9 2
    3. FirstName LastName 8.1 7.5 3
    4. FirstName LastName 1:04.84
    5. FirstName LastName 1:15.84 1:07.84

    Should return:


  63. Ashish says:

    Choice hotel | US performance report | WC 18 Dec | 24 Dec | 1700 est

    How i can split this by using formula in excel,
    As required choice hotel in different column, US performance report in different column, and 24 Dec and 1700 est in different column.

  64. Rahul says:


    can anyone help me find 036310898577 this one

  65. Tim says:

    So I have thousands of SKU numbers with design, width, and length code included. I want to break the code down as I wish. I can use the MID function but not all the codes have the same character number or sequence.
    Some examples of the SKUs:

    As you can see above first design code comes, then width and length.
    How can I break down approx. 12000 items in my list?
    Your help will be greatly appreciated.

    Happy new year,

  66. Malcolm Dixon says:


    I have 100s of rows of entries with different time stamps similar to -

    These time stamps range for a period of up to 30 days, from 8am - 11pm
    I've used LEFT and MID to create 2 new columns with date and time, such as 2021-01-25 & 12:32:56

    So I now have 100s of entries with a nice date - time format

    Now I want to get a total of how many times there's an entry recorded between 08:00-12:00 - 12:-01-16:00 - 16:01-20:00 and 20:01-23:00
    I can't work out how to do this, as you can't sum the results, as they are output from the LEFT/MID queries.

    Please help thanks :)

  67. Nimesh Zaveri says:


    I want to know that how to extract any text from the cell.
    There can be some sentences.

    Thank You...

  68. petru says:

    i hneed a little help
    i have a excel with some documents that have barcodes and i time stamp when are they created and i need to do somehow so that i know how many unfinicheddocuments i have before 14:00.the format of the cell is like this 08.03.2021 14:36:45,it is from excel extracted from e program that we use.i tried this formula : MID(D3;12;2)+IF(H3<14;"overdue";"still in frame") but is not working,separatly they are working but i tried to have just one formula.i think the error is from H3 from IF function.tks

  69. no channara says:

    My work consists of string with two occurrences of this sign ":" , i.e. Account Num.:76372/B098:COM and I want to get only 76372/B098 in a single column.

    I found the formula MID(A2,SEARCH(":",A2)+1,SEARCH(":",A2,SEARCH(":",A2)+1)-SEARCH(":",A2)-1) is very helpful and exactly solved my problems.

    Thank you so much. You really help my work more easily. :)

  70. Dayan says:

    I need the get the following characters

    FG-F19951-D02-12 = get the new colomn D02

  71. Gabriela says:

    Hello! I hope you guys can help me with my case :)

    %B6009210202107390^SMITH/JOHN I ^4912120000004825853 000 ?;6009210202107390=49121200000000000000?

    If I would want to extract "^4912120000004825853" how should I use this formula?


  72. Marc says:

    the string published above for selecting a string of letters between certain keys in that string is unfortunately wrong. The function MID requires more brackets, and uses semicolon.
    Use this one if you want to select the string between "". E.g. in field A2 you have the string: improfessionalexcel, which will give you the word "using".


  73. Marc says:

    caution, this webeditor corrupts the formulas when posting. I did type a completely different formula than the one stated in my comment above!!!!! don't use it!

  74. Lia says:

    This is awesome! I am managing an excel sheet of my expenses and I just copy pasted your formula =MID(A2,SEARCH(", ",A2)+1,SEARCH(", ",A2,SEARCH(", ",A2)+1)-SEARCH(", ",A2)-1)

    It was so accurate. Thank you for sharing this! Amazing!

  75. Swati panda says:


    I am trying to convert 30-jun-21 pm to 1:45. Please help someone with mid and substitute function together.

  76. Swati panda says:

    Thank you for the formula. It works.

Post a comment

Thank you for your comment! When posting a question, please be very clear and concise. This will help us provide a quick and relevant solution to your query. We cannot guarantee that we will answer every question, but we'll do our best :)