Left, Left$ Functions

See Also19Q70XG              Example3M7JHW>Low

Returns the leftmost n characters of a string argument.


Left[$](strexpr, n)


Left returns a Variant8PHEAW3; Left$ returns a String.

The Left[$] function has these parts:

Part               Description


strexpr           String expression1330R89 from which the leftmost characters are returned.  This can be any string expression.  However, only Left can accept a Variant of VarType7A68ZTZ 1 (Null1DDW7C0) as stringexpr, in which case, a Null is returned.

n                   Long integer expression indicating how many characters to return.  It must be between 0 and approximately 65,535, inclusive.  If n is 0, the return value is a zero-length string.  If n is greater than or equal to the number of characters in strexpr, the entire string is returned.


To find the number of characters in strexpr, use Len(strexpr).

See Also

Len FunctionLANLEN

Mid, Mid$ Function3XXKYW5

Right, Right$ FunctionQ1GJT8

Left, Left$ Function Example

The example uses the Left function to return the first of two words input by the user.  To try this example, paste the code into the Declarations section of a form.  Then press F5 and click the form.


Sub Form_Click ()

   Dim LWord, Msg, RWord, SpcPos, UsrInp       ' Declare variables.

   Msg = "Enter two words separated by a space."

   UsrInp = InputBox(Msg)                      ' Get user input.

   SpcPos = InStr(1, UsrInp, " ")              ' Find space.

   If SpcPos Then

      LWord = Left(UsrInp, SpcPos - 1)         ' Get left word.

      RWord = Right(UsrInp, Len(UsrInp) - SpcPos)    ' Get right word.

      Msg = "The first word you entered is """ & LWord

      Msg = Msg & "." & """"  & " The second word is """

      Msg = Msg & RWord & "." & """"


      Msg = "You didn't enter two words."

   End If

   MsgBox Msg                                  ' Display message.

End Sub