VBA Trim and Application.worksheetfunction.Trim

  • Thread starter Thread starter Hari Prasadh
  • Start date Start date
H

Hari Prasadh

Hi,

Not really a doubt...

Just curious as to why Microsoft has made 2 functions available in VBA, with
same name but with different results. VBA trim is concerned only with
leading spaces, while App.Wkshfunction.trim removes all spaces (except a
single space between words).

If the end results are different then, shouldnt the name of the functions be
different.
 
Apples and Oranges.

Trim() is a VBA function. It exists in any VBA environment (including
VB).

The XL TRIM() function, exposed in VBA through
Application.WorksheetFunction.Trim(), is independent of (and preceded)
VBA.

In cases where a VBA function does the same thing as an application
function, the application function isn't exposed, e.g., DATE() isn't
exposed since DateSerial() performs the same function. Since TRIM() and
Trim behave differently, TRIM is exposed.

Similarly, Application.WorksheetFunction.Round() is exposed since
ROUND() and VBA's Round() return different results when the least
significant digit is 5.
 
Excel and VBA are two separate products that have been brought together.
The trim function or equivalent is found in most programming languages and
functions pretty much as VBA's trim function. Excel, developed as a
separate product, had a trim function before the interface to VBA was
introduced in xl5.

Round, introduced in VBA6, works differently than the round function found
in Excel. I am sure there are others that don't come immediately to mind.
Replace (VBA) and Substitute (Excel) work very similarly, but don't have the
same name. I think you will just have to learn the distinctions.
 
Hi JE M and Tom,

Thanx a lot for the nice explanations you have given to me.

Highly informative.

Would remain wary of Round as well.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top