VBA - Mid


Advertisements

The Mid Function returns a specified number of characters from a given input string.

Syntax

Mid(String,start[,Length])

Parameter Description

  • String − A required parameter. Input String from which the specified number of characters to be returned.

  • Start − A required parameter. An Integer, which specifies the starting position of the string.

  • Length − An optional parameter. An Integer, which specifies the number of characters to be returned.

Add a button and add the following function.

Private Sub Constant_demo_Click()
   Dim var as Variant
   var = "Microsoft VBScript"
   msgbox("Line 1 : " & Mid(var,2))
   msgbox("Line 2 : " & Mid(var,2,5))
   msgbox("Line 3 : " & Mid(var,5,7))
End Sub

When you execute the above function, it produces the following output.

Line 1 : icrosoft VBScript
Line 2 : icros
Line 3 : osoft V
vba_strings.htm
Advertisements