Trim Function Description
The VBA Trim function removes both leading and trailing whitespaces from a string, looking from both the left and right side of the string.
The syntax for the Trim function in VBA is:
Trim( text )
The string for which you wish to remove any leading and trailing (looking from the left and right) whitespaces from.
Trim does not remove non-whitespace characters such as new lines (vbNewLine, vbCrLf) etc.
The Trim function can be used in VBA code. Let’s look at some VBA Trim function examples:
Trim " Hello world! " 'Result: "Hello world!" Trim " " & vbNewLine & " Some Text " & vbNewLine & " " 'Result: vbNewLine & " Some Text " & vbNewLine