View Single Post
  #8   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

What about the problem I'm having with the Left() function? Do i want to
reassign that value to a new variable? like:

newarraystring = Left(arraystring, InStrRev(arraystring, ",")-1)

anyway, I haven't had a chance to give your example a test yet since I
didn't work today, but I'll give it a try and see how it goes.

"Ron Rosenfeld" wrote:

On Thu, 02 Oct 2008 07:13:37 -0400, Ron Rosenfeld
wrote:

On Wed, 1 Oct 2008 10:15:01 -0700, 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.


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

is not a valid VBA statement. You will get an error message if you enter that
line.

To have arraystring equal the value you have above, your statement should be:

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

You can then strip off everything from the last comma by using:

Left(arraystring, InStrRev(arraystring, ",") - 1)

--ron


Actually, it should be:

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


but the result of the function above will be the same, as can be seen in this
demo program:

=============================
Option Explicit
Sub foo()
Dim arraystring
arraystring = """someword"", ""someword2"", ""someword3"", ""someword4"", """
Debug.Print arraystring
Debug.Print Left(arraystring, InStrRev(arraystring, ",") - 1)
End Sub
================================
--ron