The Excel MID Function
The Excel Mid function returns a specified number of characters from the middle of a supplied text string.
The syntax of the function is:
MID( text, start_num, num_chars )
Where the function arguments are:
|text||-||The original text string.|
|start_num||-||An integer that specifies the position of the first character that you want to be returned.|
|num_chars||-||An integer that specifies the number of characters (beginning with start_num), to be returned from the supplied text.|
Note that the Mid function always returns a text string, even though this may be contain digits and therefore may look like a number. You should bear this in mind if you wish to use the result of the function within further formulas.
Mid Function Examples
Column B of the spreadsheet below shows three examples of the Excel Mid function.
|1||Original Text||=MID( A1, 7, 1 )|
|2||Original Text||=MID( A2, 4, 7 )|
|3||255 years||=MID( A3, 3, 1 )|
|2||Original Text||ginal T|
Note that the example in cell B3 returns the text value "5" (not the numeric value). Excel Data Types are explained further on the Excel Formatting page.
For further information and examples of the Excel Mid function, see the Microsoft Office website.
Mid Function Error
If you get an error from the Excel Mid function, this is likely to be the #VALUE! error:
Occurs if either:
- the supplied start_num argument is < 1;
- the supplied num_chars argument is < 0.
Also, some users encounter the following problem:
Common Problem - Using the Mid Function With Dates
Some users make the mistake of attempting to use the , Left, Mid or Right functions on dates.
Dates are stored in Excel as numbers, and it is only the cell formatting that makes them appear as dates in your spreadsheet. Therefore, if you attempt use the Left, Mid or Right function on a date, the function will return the start, mid or end characters of the number that represents that date.
For example, 01/01/1980 is represented by the number 29221, so applying the Mid function to a cell containing the date 01/01/1980 (and requesting that 2 characters, starting from the 2nd character) would result in a returned value of "92".
Solution No. 1
Use the Day, Month or Year functions to extract individual parts of a date.
Solution No. 2
If you are not using the dates in other calculations, which rely on them being stored as numbers, you can convert the cells containing dates to text, using Excel's Text To Columns tool. To do this:
- Use the mouse to select the cells you want to convert to text (this must not span more than one column);
- From the Data tab on the Excel ribbon, select the Text to Columns ... option;
- Ensure the Delimited option is selected and click Next;
- Ensure all the Delimiters are unchecked and click Next;
- You should now be offered a selection of Column Data Formats. Select Text and click the Finish button.
The data in your selected cells should now be stored as text within Excel, and the Mid function will work as expected.