Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel - How do I remove characters from th left side of a string

Status
Not open for further replies.

mtmanecho

Technical User
Nov 21, 2002
4
US
I am just digging into excel and found that it would be very helpful if I could chop so many characters off of a certain cell or cells

example: "Date:" and "Request ID:" are static and unwanted

Date: 11/30/2002
Request ID: BrKUq43D

any ideas?
 
I was able to get these two cells with
=RIGHT($A$151,10)

yet I am still stumped with a name field because I do not know how long the name is going to be when It gets pasted in.

example:
name: John Doe
&
name: John Dawson

any ideas how to just strip off of the left?
 
Hi mt,

Just as with the 'right' function, use the 'len' function to find length of string.

Sorry - I don't understand what you are attempting to 'strip off'.


Regards,

Darrylle


"Never argue with an idiot, he'll bring you down to his level - then beat you with experience."
 
Use the instr function to find the location of the colon or space:

thename = activecell.value 'or whatever to get the value
locale = instr(thename," ")
surname = right(thename, len(thename)- locale + 1)

This won't work on "Cheryl Ann Smith" as it will return "Ann Smith". It will also be similarly confused by initials. You could loop it thru until locale = 0, (there are no spaces) and hope no-one has a double surname that they don't split with a dash:

thename = activecell.value 'or whatever to get the value
locale = instr(thename," ")
do
surname = right(thename, len(thename)- locale + 1)
locale = instr(thename," ")
loop until locale = 0
 
If, as you say, the entries like "Date:" and "Request ID:" are static and you know there will always be in that place, then you only need:

MyDate=mid(range("A151"),7)
MyRequestID=mid(range("A152"),13)

That's if you're using VBA (which is what this forum typically discusses). By formula, use Darrylle's approach:

=right(A151,len(A151-6))
etc


Rob
[flowerface]
 
Oops, just noticed a mistake in my post above. Make that formula
=right(A151,len(A151)-6) (i.e., shift the parenthesis around)
Rob
[flowerface]
 
This works perfect

=right(A151,len(A151)-6)

Now that I look at it, it makes total sense but for the life of me I couldn't grasp it. Thank you

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top