MID(string, start [,length])

Returns the text string which is a substring of a larger string (String).


stringThe text string (String).
startThe character position to start (Long).
length(Optional) The number of characters to return (Long).

REMARKS
* If "start" > Len("string"), then a zero length string is returned.
* If "start" is 0, then a run-time error occurs.
* The first character position is 1.
* If "string" is Null, then Null is returned.
* If "length" is left blank, then all the characters from the "start" to the end of "string" are returned.
* You can use the INSTR function to return the position of a substring within a larger string, starting at the beginning.
* You can use the INSTRREV function to return the position of a substring within a larger string, starting at the end.
* You can use the MID - Statement to replace a specified number of characters.
* You can use the MIDB function that can be used with byte data.
* You can use the MID$ function to return a String data type instead of a Variant/String data type.
* You can use the MIDB$ function to return a String data type instead of a Variant/String data type.
* You can use the REPLACE function to return a text string with a number of characters replaced.
* For more information, refer to the Finding Strings page.
* The equivalent Excel function is Application.WorksheetFunction.MID
* The equivalent .NET function is Microsoft.VisualBasic.Strings.Mid
* For the Microsoft documentation refer to docs.microsoft.com

Debug.Print Mid("hello world", 1)     '= "hello world"  
Debug.Print Mid("hello world", 2) '= "ello world"
Debug.Print Mid("abc",3) '= "c"
Debug.Print Mid("somemore", 5000, 1) '= ""
Debug.Print Mid("somemore", 1, 1) '= "s"
Debug.Print Mid("somemore", 2, 1) '= "so"
Debug.Print Mid("somemore", 5, 4) '= "more"
Debug.Print Mid("development",0) ' runtime error

Dim sString As String
sString = "123456789"
Debug.Print Mid(sString, Len(sString) - 1) '= "89"
Debug.Print Mid(sString, Len(sString) - 2) '= "789"
Debug.Print Mid(sString, Len(sString) - 3) '= "6789"

© 2021 Better Solutions Limited. All Rights Reserved. © 2021 Better Solutions Limited Top