Menu
×
   ❮   
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP C C++ C# AWS W3.CSS HOW TO BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING HTML & CSS BASH RUST TOOLS

Excel Tutorial

Excel HOME Excel Introduction Excel Get Started Excel Overview Excel Syntax Excel Ranges Excel Fill Excel Move Cells Excel Add Cells Excel Delete Cells Excel Undo Redo Excel Formulas Excel Relative Reference Excel Absolute Reference Excel Arithmetic Operators Excel Parentheses Excel Functions

Excel Formatting

Excel Formatting Excel Format Painter Excel Format Colors Excel Format Fonts Excel Format Borders Excel Format Numbers Excel Format Grids Excel Format Settings

Excel Data Analysis

Excel Sort Excel Filter Excel Tables Excel Conditional Format Excel Highlight Cell Rules Excel Top Bottom Rules Excel Data Bars Excel Color Scales Excel Icon Sets Excel Manage Rules (CF) Excel Charts

Excel PivotTables

Excel PivotTable Intro Excel Create PivotTable Excel PivotTable Values Excel PivotTable Filter Excel PivotTable Group Excel Calculated Field Excel PivotChart

Excel Case

Case: Poke Mart Case: Poke Mart, Styling

Excel Functions

AND AVERAGE AVERAGEIF AVERAGEIFS CONCAT COUNT COUNTA COUNTBLANK COUNTIF COUNTIFS DATEDIF FILTER HLOOKUP IF IFERROR IFS INDEX INDEX MATCH LEFT LEN LOWER MATCH MAX MEDIAN MID MIN MODE NETWORKDAYS NPV OR PROPER RAND RIGHT ROUND SORT STDEV.P STDEV.S SUBSTITUTE SUM SUMIF SUMIFS SUMPRODUCT TEXTJOIN TODAY TRIM UNIQUE UPPER VLOOKUP XLOOKUP XOR

Excel How To

Convert Time to Seconds Difference Between Times NPV (Net Present Value) Remove Duplicates

Excel Cert

Excel Certificate

Excel Examples

Excel Exercises Excel Syllabus Excel Study Plan Excel Training

Excel References

Excel Keyboard Shortcuts


Excel MID Function


Share

MID Function

The MID function is a premade function in Excel, which returns characters from the middle of a text.

You choose where to start, and how many characters to return. It works like LEFT and RIGHT, but it can start at any position in the text.

It is typed =MID and has the following parts:

=MID(text, start_num, num_chars)

Note: The different parts of the function are separated by a symbol, like comma , or semicolon ;

The symbol depends on your Language Settings.

Text: The text to take characters from. This is usually a cell.

Start_num: The position of the first character to return. The first character in the text is position 1.

Num_chars: How many characters to return.

The item code PKB-0200-BALL has 13 characters. This is the position of each one:

Position12345678910111213
CharacterPKB-0200-BALL

=MID(B2, 5, 4) starts at position 5 and returns 4 characters. If B2 holds PKB-0200-BALL, the result is 0200.

How to use the MID function:

  1. Select a cell (C2)
  2. Type =MID
  3. Double click the MID command
  4. Select the cell with the text (B2)
  5. Type (,)
  6. Type the position to start at (5)
  7. Type (,)
  8. Type the number of characters to return (4)
  9. Hit enter

Let's have a look at an example!

These are the products in the Poke Mart shop, with their item codes. Copy them and paste them into cell A1 to follow along:

Example data

AB
1ProductItem Code
2Poke BallPKB-0200-BALL
3Great BallGRB-0600-BALL
4Ultra BallULB-1200-BALL
5PotionPOT-0300-MEDS
6Super PotionSPT-0700-MEDS
7Hyper PotionHPT-1200-MEDS
8ReviveREV-1500-MEDS
9AntidoteANT-0100-STAT
10Paralyze HealPRH-0200-STAT
11AwakeningAWK-0250-STAT

Each item code has three parts, separated by dashes: a short name for the item, the price with four digits, and the category.

Type the label Price in C1.

Use the MID function to get the price from the middle of each code:

ABC
1ProductItem CodePrice
2Poke BallPKB-0200-BALL0200
3Great BallGRB-0600-BALL0600
4Ultra BallULB-1200-BALL1200
5PotionPOT-0300-MEDS0300
6Super PotionSPT-0700-MEDS0700
7Hyper PotionHPT-1200-MEDS1200
8ReviveREV-1500-MEDS1500
9AntidoteANT-0100-STAT0100
10Paralyze HealPRH-0200-STAT0200
11AwakeningAWK-0250-STAT0250
=MID(B2, 5, 4)

MID starts at character 5 in B2 and returns 4 characters. For PKB-0200-BALL, that is 0200.

The function is repeated with the filling function for each row, down to C11.



MID Returns Text

Look at column C again. The prices are aligned to the left, and 0200 keeps its zero at the start.

That is because MID always returns text, also when the characters are digits. Excel does not calculate with text. If you add up C2:C11 with SUM, the result is 0.

Put MID inside the VALUE function to change the text into a number. Type the label Price (number) in D1, and the formula in D2. Fill it down to D11.

Then type the label Sum in A12, =SUM(C2:C11) in C12 and =SUM(D2:D11) in D12:

ABCD
1ProductItem CodePricePrice (number)
2Poke BallPKB-0200-BALL0200200
3Great BallGRB-0600-BALL0600600
4Ultra BallULB-1200-BALL12001200
5PotionPOT-0300-MEDS0300300
6Super PotionSPT-0700-MEDS0700700
7Hyper PotionHPT-1200-MEDS12001200
8ReviveREV-1500-MEDS15001500
9AntidoteANT-0100-STAT0100100
10Paralyze HealPRH-0200-STAT0200200
11AwakeningAWK-0250-STAT0250250
12Sum06250

The formula in D2:

=VALUE(MID(B2, 5, 4))

The formula in D12:

=SUM(D2:D11)

The prices in column D are numbers. They are aligned to the right, and SUM returns 6250. The same SUM on the text in column C returns 0.

Note: You can also multiply the result by 1, like =MID(B2, 5, 4)*1. A calculation changes text with only digits into a number.


At the End of the Text

If num_chars asks for more characters than there are left, MID returns the characters up to the end of the text. If start_num is after the last character, MID returns an empty text.

Type PKB-0200-BALL in A2, A3 and A4 of a new sheet:

AB
1CodeResult
2PKB-0200-BALLBALL
3PKB-0200-BALLBALL
4PKB-0200-BALL

The formulas in B2, B3 and B4:

=MID(A2, 10, 4)
=MID(A3, 10, 100)
=MID(A4, 20, 4)

B2 asks for exactly the last 4 characters, BALL.

B3 asks for 100 characters. There are only 4 left from position 10, so MID returns BALL without an error.

B4 starts at position 20, but the text has only 13 characters. The result is an empty text, so the cell looks empty.

If start_num is less than 1, or num_chars is less than 0, MID returns the #VALUE! error.


Going Further: MID With FIND

In the codes above, the price always starts at position 5. In some lists, the first part of a code has a different length in each row, so the start position changes too.

Then use the FIND function to find the position of the dash. FIND returns the position of a text inside another text, counted from the left:

=FIND(find_text, within_text)

These codes start with the name of the item, so the first part has a different length in each row:

ABC
1CodeDash AtPrice
2POKE-0200-BALL50200
3GREAT-0600-BALL60600
4ULTRA-1200-BALL61200
5POTION-0300-MEDS70300
6REVIVE-1500-MEDS71500
7ANTIDOTE-0100-STAT90100

The formula in B2 finds the position of the first dash:

=FIND("-", A2)

The formula in C2 starts one character after the dash, and returns 4 characters:

=MID(A2, B2+1, 4)

For POKE-0200-BALL, the dash is character 5, so MID starts at 6. For ANTIDOTE-0100-STAT, the dash is character 9, so MID starts at 10. The price is found in every row.

You do not need the helper column B. Put FIND inside MID to do it all in one cell:

=MID(A2, FIND("-", A2)+1, 4)

Note: FIND is case-sensitive, and returns #VALUE! if the text is not found. FIND looks for the first dash only, so it does not matter that the codes have two.


Related Functions

MID is often used together with LEFT, RIGHT and LEN. To change characters instead of taking them out, use SUBSTITUTE.


Free account

Track your progress

XP earned 0 Day streak 0 Spaces 0 League —

New

Learn in Adventure Mode W3Schools Adventure App

Coding fundamentals as bite-sized lessons and challenges.

×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookies and privacy policy.

Copyright 1999-2026 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.