VBA Mid function

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)

Mid Function Description

The VBA Mid function extracts a substring from a given string, based on a given position within the string and a number of characters to extract.

If you want to get a substring starting from the left use Left and if you want to get a substring starting from the right (the end of the string) use Right.


The syntax for the Mid function in VBA is:

MID( text, start_position, no_of_characters )


The string from which you wish to extract from.

The index position in the string that the function is to begin extracting from. The first index position in the string is 1.

The number of characters that you wish to extract.

Other Notes

The string index position in the Mid, Left and Right functions starts at 1.

Example usage

The Mid function can be used in VBA code. Let’s look at some VBA Mid function examples:

Mid "Hello World!", 6, 6
'Result: "World"

Mid "Hello World!", 1, 5
'Result: "Hello"

Simply the best place to learn Excel VBA