VBA: Mid function

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading...

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.

Syntax

The syntax for the Mid function in VBA is:

MID( text, start_position, no_of_characters )

Parameters

text
The string from which you wish to extract from.

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

no_of_characters
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 VBA!

Error: Please enter a valid email address

Error: Invalid email

Error: Please enter your first name

Error: Please enter your last name

Error: Please enter a username

Error: Please enter a password

Error: Please confirm your password

Error: Password and password confirmation do not match