Show Buttons
Share On Facebook
Share On Twitter
Share On Google Plus
Share On Linkdin
Share On Reddit
Contact us
Hide Buttons

VBA-Excel: String Functions – Mid()


The Mid() func­tion returns sub­string from a string and size of the sub­string is decided based on the para­me­ters provided.


Mid (strMainString,start[,length])

  • str­Main­String
    • Manda­tory
    • Type: String
    • Sub­string will be returned from this main string.

  • Start
    • Manda­tory
    • Type: Numeric
    • Start­ing posi­tion of a sub­string, if start > No Of char­ac­ters in main string then Mid() will return zero-length string(“”).
  • Length
    • Optional
    • Type: Numeric
    • No of char­ac­ters to be taken from the start­ing posi­tion. If not pro­vided, all the char­ac­ters after start­ing posi­tion are taken.
Function FnMid()

    Dim strMainString

    strMainString = "This is just an example"

    MsgBox "SubString is '" & Mid(strMainString, 2, 15) & "'"

End Function


Also Read About  Other String() Functions

INSTR()                       |                         Instr­REV()                       |                        LCase()

UCase()                      |                         Left()                                |                        Right()

LTrim()                        |                         Mid()                                 |                        Trim()

RTrim()                       |                        Replace()                          |                        Space()

Len()                           |                        Str­Comp()                         |                        String()


Happy Macro­ing :)

Sumit Jain


You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: