Show Buttons
Share On Facebook
Share On Twitter
Share On Google Plus
Share On Linkdin
Share On Reddit
Contact us
Hide Buttons

VBA-Excel: String Functions – Trim()


The Trim func­tion removes spaces on the left and right side of a string.


Trim (str­Main­String)

  • str­Main­String
    • Manda­tory
    • 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()                       |                         Instr­REV()                       |                        LCase()

UCase()                      |                         Left()                                |                        Right()

LTrim()                        |                         Mid()                                 |                        Trim()

RTrim()                       |                        Replace()                          |                        Space()

Len()                           |                        Str­Comp()                         |                        String()

Happy Macro­ing :)

Sumit Jain


You may also like...

2 Responses

  1. Jason says:

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

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

%d bloggers like this: