« Quote of the day | Main | Taking the PMP Exam - Appendix B - Contract Types »

MS Project VBA - Trim Function

Solving a recent custom field formula problem required reaching into the toolbox and pulling out the trim() string function. Trim is one of the simplest string functions. It does one thing and does it well. It just strips any leading or trailing spaces from a text string. So if you have a string like this:

myString = " There is space in front and in back "

you can use:

trim(mystring)

to return "There is space in front and in back"

The problem was that converting a Microsoft Project Unique ID to a string adds a leading space to the string (why? I don't know, but it does) so you can use trim to obtain just the characters you want.

Trim is not just a VBA function, you can use it in Excel formulas, MS Project custom field formulas and just about any programming language I've seen. I've used it extensively with spreadsheets that contain data pasted in from other sources.

RELATED POSTS
  • VBA Writing to a text file (MS Project, Excel)
  • Using a ComboBox in a Microsoft Project Userform
  • Microsoft Project 2007 VBA Help now Available Online
  • Microsoft Project Performance Limitations
  • Microsoft Project 2007 Example Project Templates
  • Eight Miles High - Microsoft MVP Summit
  • Microsoft Project 2007 Bugs - Project Server too...
  • Microsoft Project 2007 Import Problems
  • VB / C# robotic car
  • Microsoft Project 2007 Released

  • Comments (1)

    JohnB:

    You wrote "The problem was that converting a Microsoft Project Unique ID to a string adds a leading space to the string (why? I don't know, but it does) ..."

    While this is true, you should note that when working in VBA there is no leading space. For example:

    In the P2003 Pro immediate window

    ?""

    shows

    A macro which loops through all tasks displaying:
    ""

    also doesn't show any leading spaces.

    Post a comment

    (Comments are moderated to fight SPAM and will be published after I have a chance to approve them. Thanks for waiting.)

    About

    The previous article is Quote of the day.

    The next article is Taking the PMP Exam - Appendix B - Contract Types.

    Current articles are in the main index page and you can find a complete list of articles in the archives.

    Creative Commons License
    This weblog is licensed under a Creative Commons License.
    Powered by
    Movable Type 3.34