Be the first user to complete this post

  • 0
Add to List

VBA-Excel: String Functions – Mid()

Description: 

The Mid() function returns substring from a string and size of the substring is decided based on the parameters provided.

Format:

Mid (strMainString,start[,length])

Arguments:
  • strMainString
    • Mandatory
    • Type: String
    • Substring will be returned from this main string.

  • Start
    • Mandatory
    • Type: Numeric
    • Starting position of a substring, if start > No Of characters in main string then Mid() will return zero-length string(“”).
  • Length
    • Optional
    • Type: Numeric
    • No of characters to be taken from the starting position. If not provided, all the characters after starting position are taken.
Function FnMid()

    Dim strMainString

    strMainString = "This is just an example"

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

End Function
Mid()
Mid()

Also Read About  Other String() Functions

INSTR()                       |                         InstrREV()                       |                        LCase()

UCase()                      |                         Left()                                |                        Right()

LTrim()                        |                         Mid()                                 |                        Trim()

RTrim()                       |                        Replace()                          |                        Space()

Len()                           |                        StrComp()                         |                        String()



Also Read:

  1. VBA-Excel: Array Functions – Join() – Converts Array to String
  2. VBA Excel - Cells, Ranges and Offset: Refer to Cells by Using Shortcut Notation
  3. VBA-Excel: Arrays – One Dimension, Static Array
  4. VBA-Excel: Get all the WeekDays or Working days in Specified Date Range, (excluding Satudays and Sundays)
  5. VBA-Excel : Strings Functions – InstrRev
  6. VBA-Excel: Date-Time Functions – DateValue()
  7. VBA-Excel: Date-Time Functions – TimeSerial() and TimeValue()
  8. VBA-Excel: String Functions – strComp()