Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, and 2013. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Dissecting a String.

Dissecting a String

by Allen Wyatt
(last updated April 18, 2017)


If you have used BASIC before, you will be right at home with the string functions provided by VBA. The following table details the most common string functions and what they return.

Function Comments
Left(Source, Count) Returns the left Count characters of Source text.
Mid(Source, Start [, Count]) Returns the portion of Source text beginning with the Start character. If Count is supplied, then the result is limited to that many characters.
Right(Source, Count) Returns the right Count characters of Source text.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (12574) applies to Microsoft Excel 2007, 2010, and 2013. You can find a version of this tip for the older menu interface of Excel here: Dissecting a String.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He  is president of Sharon Parq Associates, a computer and publishing services company. ...


Working on Shared Templates

In many companies it is common to have standard templates accessible through the internal network. If you have templates ...

Discover More

Determining the Number of Bookmarks Defined in a Document

If you develop a macro that needs to work with bookmarks defined in a document, it is inevitable that you will need a way ...

Discover More

Removing Duplicates Based on a Partial Match

Some types of data may have certain fields that contain partially identical information. In such cases you may want to ...

Discover More

Solve Real Business Problems Master business modeling and analysis techniques with Excel and transform data into bottom-line results. This hands-on, scenario-focused guide shows you how to use the latest Excel tools to integrate data from multiple tables. Check out Microsoft Excel 2013 Data Analysis and Business Modeling today!

More ExcelTips (ribbon)

Specifying a Delimiter when Saving a CSV File in a Macro

You can, within a macro, save a workbook in several different file formats that are understood by Excel. However, you may ...

Discover More

Extracting Proper Words

If you've got a list of potential words, and you want to know which of those potential words are real, you'll appreciate ...

Discover More

Understanding Functions in Macros

Functions are a common programming construct. They help you to create easy ways of processing information and returning a ...

Discover More

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.


If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is one more than 5?

2017-04-20 10:36:22

Peg Molter

Thanks so much for the clarification, guys. It all makes sense now!

2017-04-20 04:39:27

Alan Elston

Hi Willy, Hi Micky
Hi Peg Molter,
As Willy said we are talking in this Blog about the VBA Strings collection function MID.
The Excel VBA documentation seems to be getting increasingly bad and I often mix Excel Spreadsheet Functions and VBA Functions up.
For VBA Strings Functions you are best looking at some old VB documentation, such as
You will also there find the gem of info that you can use Mid on the left side of an assignment statement, where you can replace a substring within a string.
In VBA the differences are not a great problem, as you have the Evaluate Method which allows you to do most spreadsheet things within VBA.
Doing it the other way around is not too difficult either. Even if you are not familiar with VBA, I would strongly recommend learning the very basics so that you could, for example, make your own MID function. Then you could arrange that you had a MIDPEG function, that will work for you in the spreadsheet just as VBA Strings collection MID works.
So this would be your VBA code to make your MIDPEG function. You put that in a Normal Code Module.

Public Function MIDPEG(ByVal Str As String, ByVal Stt As Long, Optional Lenf As Long) As String '
If Lenf = 0 Then
Let MIDPEG = Mid(Str, Stt)
Let MIDPEG = Mid(Str, Stt, Lenf)
End If
End Function

After that, if you type =MIDPEG in any cell you will be able to use it just like the MID function in VBA, that is to say you can omit the last Count argument.
Try it in this File, ( you will need to enable macros , if prompted to do it on opening ).
If you are not too familiar with macros then check out some of Allen’s info on macros


2017-04-20 03:16:43

Michael (Micky) Avidan

@Peg Molter,
In addition to Willy Vanhaelen's explanation - I would like to emphazise that (in VBA) if the Num_chars argument is omitted or if there are fewer than Length characters in the text (including the character at position Start), all characters from the Start position to the End of the string - are returned.
Michael (Micky) Avidan
“Microsoft® Answers" - Wiki author & Forums Moderator
“Microsoft®” MVP – Excel (2009-2017)

2017-04-19 12:15:36

Willy Vanhaelen

@Peg Molter
The Count argument is not optional in the Excel MID function but, as mentioned in the first sentence, this tip is about VBA (Visual Basic for Applications, used in Excel macros) and there it is optional.
SomeVariable = Mid("VBA Mid function",5,3) returns "Mid"
SomeVariable = Mid("VBA Mid function",5) returns "Mid function"

2017-04-18 07:44:50

Peg Molter

The argument Count is not optional for the MID function. I tried it without it, wondering what it would return. It returned an ERROR and told me I had too few arguments.

This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.