Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 65
Default replace last character in string

How can i replace last character in a string?
--
help a friend help you
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default replace last character in string

Maybe this

myString = Range("A1").Value
NewEnd = "W"
myString = Left(myString, Len(myString) - 1) & NewEnd
Range("A1").Value=myString

Mike

"ernie" wrote:

How can i replace last character in a string?
--
help a friend help you

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default replace last character in string

This is one way...

StrVariable = Left(StrVariable, Len(StrVariable) - 1) & YourNewCharacter

--
Rick (MVP - Excel)


"ernie" wrote in message
...
How can i replace last character in a string?
--
help a friend help you


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 117
Default replace last character in string

To replace last character in string called strTemp with a "G" use this

strTemp = Left(strTemp, Len(strTemp) - 1) & "G"

"ernie" wrote:

How can i replace last character in a string?
--
help a friend help you

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default replace last character in string

If your text is in a simple variable, then you can also do it this way...

Mid(StrVariable, Len(StrVariable), 1) = YourNewCharacter

This is more efficient than using the concatenation method I posted earlier,
but it requires your text to be in a simple variable (not a Range or other
text holding object) in order to work.

--
Rick (MVP - Excel)


"Rick Rothstein" wrote in message
...
This is one way...

StrVariable = Left(StrVariable, Len(StrVariable) - 1) & YourNewCharacter

--
Rick (MVP - Excel)


"ernie" wrote in message
...
How can i replace last character in a string?
--
help a friend help you





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default replace last character in string

And just to "have fun" (in other words, do not actually use what
follows<g), here is a method that works as long as your text is in not a
Unicode font (that is, it only uses ASCII/ANSI character codes of 32 to
255)...

Temp = Split(StrConv(StrVariable, vbUnicode), Chr(0))
Temp(UBound(Temp) - 1) = YourNewCharacter
StrVariable = StrConv(Join(Temp, Chr(0)), vbFromUnicode)

where you would Dim the Temp variable as either a Variant or a dynamic
String array.

--
Rick (MVP - Excel)


"Rick Rothstein" wrote in message
...
If your text is in a simple variable, then you can also do it this way...

Mid(StrVariable, Len(StrVariable), 1) = YourNewCharacter

This is more efficient than using the concatenation method I posted
earlier, but it requires your text to be in a simple variable (not a Range
or other text holding object) in order to work.

--
Rick (MVP - Excel)


"Rick Rothstein" wrote in message
...
This is one way...

StrVariable = Left(StrVariable, Len(StrVariable) - 1) & YourNewCharacter

--
Rick (MVP - Excel)


"ernie" wrote in message
...
How can i replace last character in a string?
--
help a friend help you




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Replace a character by it's place in a string John Wilson Excel Programming 2 May 1st 07 02:51 AM
Replace font of one character in a string PaulS Excel Programming 3 January 13th 07 03:45 AM
How replace a character in a string of characters? Chet Excel Programming 6 December 6th 06 01:54 AM
Replace character in string, not document KS[_2_] Excel Programming 3 October 26th 06 05:06 PM
How do I replace * as a character in a string in Excel? nicolegt Excel Programming 1 January 21st 05 10:42 AM


All times are GMT +1. The time now is 05:47 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"