View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Jonathan Brown Jonathan Brown is offline
external usenet poster
 
Posts: 47
Default Remove the right most 3 characters from a string

well...to be completely honest, which I know I should have been from the
beginning, I'm not using VBA, per se. I'm using Visual Studio Tools for
Office, so it's really just VB...for the most part. I don't have a
references option under the tools menu in Visual Studio. But I have imported
the excel.interop namespace to my project. This also means that this post
should go in the MSDN VSTO forum. But I would think that the Left() or
Right() functions would exist in either VBA, VSTO, or just plain old VB. But
I could easily be mistaken. I'll go ahead and repost this in the Visual
Studio Tools for Office forum and see if they can help me there. I
appreciate your help nonetheless.

"Tom Hutchins" wrote:

That error sounds like VBA doesn't know what the Left() or Right() functions
are. In the Visual Basic Editor, if you select Tools References, are there
checkmarks by "Visual Basic for Applications" and "Microsoft Excel 11.0
Object Library" (you might have a different version of the second one)?

Hutch

"Jonathan Brown" wrote:

I'm getting the same error on the Left() function now as I was with the
Right() function. It says, "'Public Property Left() as Integer' has no
parameters and its return type cannot be indexed."

I found this website:
http://www.entisoft.com/estools/stir...pulations.html and it has an
example using a function called StripRightNCharacters() that looks like it'll
do what I want but it doesn't appear to be valid or available function that I
can use.

any other ideas?

"Tom Hutchins" wrote:

You are getting an error on the RIGHT function because you are not passing it
the first argument it needs, which is the string to examine. However, your
approach wouldn't work anyway, because the TRIM function only removes leading
& trailing spaces from a string. Try:

ArrayString = Left(ArrayString, Len(ArrayString) - 3)

Hope this helps,

Hutch

"Jonathan Brown" wrote:

I'm using a loop to build a string of characters but I'm getting extra
characters at the end that I don't want. Is there a function like trimend or
regexp where I can take the string and remove the right most 3 characters?

Here's an example:

arraystring = "someword", "someword2", "someword3", "someword4", "

I'd like it to change my arraystring to show just:

"someword", "someword2", "someword3", "someword4"

This doesn't seem to work for me:
ArrayString = Trim(ArrayString, Right(Len(ArrayString) - 3))

I'm getting an error under the right() function.