The VBA TRIM function is listed under the text category of VBA functions. When you use it in a VBA code, it removes the leading and trailing spaces from the value supplied. In simple words, if there’s a space before and after the value it will remove it and returns the rest of the value in the result.
Syntax
Trim(String)
Arguments
- String: A text string from which you want to remove the leading and trailing spaces.
Example
To practically understand how to use the VBA TRIM function, you need to go through the below example where we have written a vba code by using it:
Sub example_TRIM()
Range("B1").Value = Trim(Range("A1"))
End Sub
In the above code, we have used the TRIM to remove all the unwanted spaces (from the left and right sides) from cell A1.
More Tutorials
⇠ Back to VBA Function List | What is VBA in Excel
Helpful Links – Developer Tab – Visual Basic Editor – Run a Macro – Personal Macro Workbook – Excel Macro Recorder – VBA Interview Questions – VBA Codes
Notes
- If the supplied string is NULL, then it will return NULL in the result.