VBA-Excel: String Functions – Trim()


The Trim function removes spaces on the left and right side of a string.


Trim (strMainString)

  • strMainString
    • Mandatory
    • Type: String
    • String whose both side spaces needs to be trimmed.


Function FnTrim()

   Dim strMainString

   strMainString = "   Sumit Jain  "

   MsgBox "Hello" & Trim(strMainString) & "Trimmed both sides."

End Function


Also Read About  Other String() Functions

INSTR()                       |                         InstrREV()                       |                        LCase()

UCase()                      |                         Left()                                |                        Right()

LTrim()                        |                         Mid()                                 |                        Trim()

RTrim()                       |                        Replace()                          |                        Space()

Len()                           |                        StrComp()                         |                        String()

Happy Macro­ing :)

Sumit Jain


You may also like...

2 Responses

  1. Jason says:

    Rtrim (str­Main­String) <== should be Trim(str­Main­String)

Leave a Reply to Jason Cancel reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: