Excel - MID Function



MID Function

The LEFT, RIGHT, and MID functions are the most prominent and commonly deployed functions for text manipulation and data cleansing in Microsoft Excel. The Excel MID function retrieves a certain number of characters from the center of the input string. The user specifies the source string, starting placement, and length of the characters supplied to the MID function. Whatever the preferred language setting in Excel, the MID function will recognize each character as 1.

Compatibility

The MID function is compatible with the following versions of MS-Excel −

  • Excel for Microsoft 365
  • Excel for Microsoft 365 for Mac
  • Excel for the web
  • Excel 2024
  • Excel 2024 for Mac
  • Excel 2021
  • Excel 2021 for Mac
  • Excel 2019
  • Excel 2016

Syntax

The syntax of the MID function is as follows −

MID(text, start_num, num_chars)

Arguments

You can use the following arguments with the MID function −

Argument Description Required / Optional
Text A text string to fetch the single/multiple characters. Required
start_num The index position of the starting character in the input string to begin the character’s extraction. Required
num_chars A numeric value representing the amount of characters to be retrieved from the input string Required

Points To Remember

  • If the start_num contains a nonpositive value, the MID function will retrieve the #VALUE! error.
  • If start_num is larger than the string length, then the MID function will retrieve the empty string.
  • If the num_chars argument contains a value less than zero, then the MID function will return the #VALUE! error.

How to use the MID function in Excel?

The step-by-step instructions to utilize the MID function are given below.

  • Open the designated Excel worksheet.
  • Select the specific cell and type the = sign, then type the MID("text"/cell reference, start_num, num_chars). The text string must be enclosed in the double quotes.
  • Press the Enter tab to obtain the final value.

Examples of MID Functions are Discussed in the Next Section

Example 1: How to Apply the MID Function in a Worksheet?

The MID function in Excel extracts a substring from text, starting at a specified position and for a set number of characters.

Solution

Step 1 − First, assume the sample dataset consists of four columns: Text, Start_num, Num_chars, and Result.

How to apply MID function in a worksheet1

Step 2 − After that, select the range D2:D12 and type the formula =MID(A2,B2,C2) in the formula bar.

How to apply MID function in a worksheet2

Furthermore, press the "ctrl+Enter" keys to get the resultant value in the selected range.

How to apply MID function in a worksheet3

As you can observe in the screenshot, if the Start_num and Num_chars are negative, then in the scenario, the MID function retrieves the #VALUE! error, as showcased in the D11 and D12 cells.

Example 2

If start_num is larger than the string length, then the MID function will retrieve the empty string.

Solution

First, you may enter the formula =MID(A3,20,4) in the B3 cell. In this expression, the second argument is larger than the input string.

MID Function Retrieve Empty String1

After that, press the Enter tab. Therefore, the MID function retrieves the empty string.

MID Function Retrieve Empty String2

Download Practice Sheet

You can download and use the sample data sheet to practice the MID function.

Advertisements