Contents
Index 🔎︎
\Mid function\\Mid statement\

# Mid Function, Mid Statement

Returns the specified portion of a string expression (\Mid function\), or replaces the portion of a string expression with another string (\Mid statement\).

### Syntax:

    Mid (Text As String, Start As Long [, Length As Long]) or Mid (Text As String, Start As Long , Length As Long, Text As String)

### Return value:

String (only by Function)

### Parameters:

\Text:\ Any string expression that you want to modify.

Start: Numeric expression that indicates the character position within the string where the string portion that you want to replace or to return begins. The minimum allowed value is 1. The maximum allowed value is 2,147,483,648.

Length: Numeric expression that returns the number of characters that you want to replace or return. The maximum allowed value is 2,147,483,648.

If the Length parameter in the \Mid function\ is omitted, all characters in the string expression from the start position to the end of the string are returned.

If the Length parameter in the \Mid statement\ is less than the length of the text that you want to replace, the text is reduced to the specified length.

\Text:\ The string to replace the string expression (\Mid statement\).

### Error codes:

5 Invalid procedure call

### Example:

    Sub ExampleUSDate
    Dim sInput As String
    Dim sUS_date As String
        sInput = InputBox("Please input a date in the international format 'YYYY-MM-DD'")
        sUS_date = Mid(sInput, 6, 2)
        sUS_date = sUS_date & "/"
        sUS_date = sUS_date & Right(sInput, 2)
        sUS_date = sUS_date & "/"
        sUS_date = sUS_date & Left(sInput, 4)
        MsgBox sUS_date
    End Sub

נושאים קשורים

String functions