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. ...


Limiting Entries to Numeric Values

When creating a worksheet, you may need to limit what can be entered into a particular cell. Using data validation you can ...

Discover More

Checking for Messages in Cells

If you have a range of cells used to display error messages, you soon discover that it is easy to miss messages that may ...

Discover More

Combining Numbers and Text in a Cell

There are times when it can be beneficial to combine both numbers and text in the same cell. This can be easily done using a ...

Discover More

Professional Development Guidance! Four world-class developers offer start-to-finish guidance for building powerful, robust, and secure applications with Excel. The authors show how to consistently make the right design decisions and make the most of Excel's powerful features. Check out Professional Excel Development today!

More ExcelTips (ribbon)

Using Seek In a Macro

When reading information from a text file, your macro may need to start reading at a place other than the beginning of the ...

Discover More

Working with Colors in a Macro

The colors used in a Excel are not as simple as they used to be. Here are some ideas relative to working with those colors in ...

Discover More

Creating a Plus/Minus Button

Want a quick way to convert positive values to negative and vice versa? You can create your own plus/minus button by using 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 8 - 2?

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.