TOP

VBA Function: Mid

YouLibreCalc for Excel logo

Description

The VBA MID Function returns the specified number of characters from a character string starting with the defined character number.


MID Syntax

Mid(text, start_character)

Mid(text, start_character, number_characters)

VBA Mid Example

Extract different portions of text from the string:

Sub MidExample()
    
     MsgBox Mid("www.moonexcel.com.ua", 1, 1)  'Returns: w
     MsgBox Mid("www.moonexcel.com.ua", 1, 3)  'Returns: www
     MsgBox Mid("www.moonexcel.com.ua", 1, 13) 'Returns: www.moonexcel
     MsgBox Mid("www.moonexcel.com.ua", 1, 30) 'Returns: www.moonexcel.com.ua
    
     MsgBox Mid("www.moonexcel.com.ua", 5, 9)  'Returns: moonexcel
     MsgBox Mid("www.moonexcel.com.ua", 5, 4)  'Returns: moon
     MsgBox Mid("www.moonexcel.com.ua", 9, 5)  'Returns: excel
     MsgBox Mid("www.moonexcel.com.ua", 16, 3) 'Returns: com
     MsgBox Mid("www.moonexcel.com.ua", 5, 50) 'Returns: moonexcel.com.ua
     MsgBox Mid("www.moonexcel.com.ua", 5)     'Returns: moonexcel.com.ua

End Sub