Excel VBA Trim Function | vba trim
Home[1]»VBA-Functions[2]»VBA-Trim-FunctionRelatedFunctions:VBALTrimVBARTrim[3][4]DescriptionTheVBATrimfunctionremovestheleadingandtrailingspacesfromasuppliedtextstring.Thesyntaxofthefunctionis:Trim(String)WheretheStringargumentisthetextstringthatyouwanttoremovetheleadingandtrailingspacesfrom.VBATrimFunctionExamplesThefollowingexampleshowshowtheVBATrimfunctioncanbeusedtoremoveoneormoreleadingand/ortrailingspacesfromthreedifferenttextstrings.DimnameAsStringDimaddressAsStringDimpostcodeAsString...
Related Functions:
VBA LTrimVBA RTrim[3][4]DescriptionThe VBA Trim function removes the leading and trailing spaces from a supplied text string.
The syntax of the function is:
Trim( String )
Where the String argument is the text string that you want to remove the leading and trailing spaces from.
VBA Trim Function ExamplesThe following example shows how the VBA Trim function can be used to remove one or more leading and/or trailing spaces from three different text strings.
Dim name As StringDim address As StringDim postcode As String
name = "John Smith " address = " 21 Smithson Street" postcode = " AB1 1CD "
name = Trim( name )address = Trim( address )postcode = Trim( postcode )
As required, the Trim function in the above VBA code has removed all leading and trailing spaces from the supplied text strings.
Return to the List of VBA Functi...