Wednesday, October 9, 2013

VBA String Functions - Part 6

LTRIM Function (VBA)

In Microsoft Excel, the LTRIM function removes leading spaces from a string.

Syntax

LTRIM( text )
text is the string that you wish to remove leading spaces from.

VBA Function Example

The LTRIM function can only be used in VBA code in Microsoft Excel. Here are some examples of what the LTRIM function would return:

LTRIM("  Google com") would return "Google com"
LTRIM("  Alphabet") would return "Alphabet"
LTRIM("  Alphabet  ") would return "Alphabet  "


Dim sResult As String
sResult = LTrim("   Alphabet   ")

The variable sResult would now contain the value of "Alphabet  ".




RTRIM Function (VBA)


In Microsoft Excel, the RTRIM function removes trailing spaces from a string.

Syntax

The syntax for the RTRIM function is:

RTrim( text )
text is the string that you wish to remove trailing spaces from.

VBA Function Example


The RTRIM function can only be used in VBA code in Microsoft Excel. Here are some examples of what the RTRIM function would return:


RTrim("Google Search  ") would return "Google Search"
RTrim("  Alphabet  ") would return "  Alphabet"


Dim sResult As String
sResult = RTrim("   Alphabet   ")

The variable sResult would now contain the value of "   Alphabet".


TRIM Function ( VBA)


In Microsoft Excel, the TRIM function returns a text value with the leading and trailing spaces removed.

Syntax

The syntax for the TRIM function is:

TRIM( text )
text is the text value to remove the leading and trailing spaces from.

VBA Function Example

Dim sResult As String
sResult = Trim ("   Alphabet   ")

The variable sResult would now contain the value of "Alphabet".

No comments:

Post a Comment

Data base function

Database function Daverage function      Averages the values in a field (column) of records in a list or database that match conditio...