Solved

I would like to cut the first character of a string if it starts with a T in MS excel

Posted on 2011-03-08
9
198 Views
Last Modified: 2012-05-11
I have a column of cells that have numbers in them.   Some start with a T and some don't.  I would like to cut the T from the cells that start with a T and leave the others alone.  
0
Comment
Question by:dmalovich
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 10

Expert Comment

by:cdebel
ID: 35068779
you could do something like this... if your data is in column A:

=IF(LEFT(A1,1)="T", MID(A1,2,LEN(A1)-1))
0
 
LVL 10

Expert Comment

by:cdebel
ID: 35068793
i forgot the FALSE part of the IF...

Sorry for that, here's the modification:
=IF(LEFT(A1,1)="T", MID(A1,2,LEN(A1)-1), A1)

You could also add UPPER statement to make it work no mather if the T is capital or not, like this:
=IF(UPPER(LEFT(A1,1))="T", MID(A1,2,LEN(A1)-1), A1)
0
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 35068811
(NFP)
The test will not be case sensitive, so there is no need for UPPER here, FYI.
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 10

Expert Comment

by:cdebel
ID: 35068850
true rorya.  Thanks for advising me.  I've never noticed that but Excel doesn't seems to make the difference between "t" and "T" in this case.  I wonder why.

@dmalovich: use the 1st line of my last comment since the upper is not necessary.
=IF(LEFT(A1,1)="T", MID(A1,2,LEN(A1)-1), A1)
0
 

Author Comment

by:dmalovich
ID: 35068863
You do have the answer for putting the formula in a cell.  I'm looping through values in vba and would like to chop off the T if its the first character and leave it as is if it is not. example vba

position = Worksheets("something").Cells(1, 1).Value

  if position has a T as first character
      then chop it off
end if  

Is this possible?
0
 
LVL 50

Expert Comment

by:barry houdini
ID: 35068892
Here's another option.....

=REPLACE(A1,1,(LEFT(A1)="T"),"")

As Rory says that isn't case-sensitive so it will remove both "T" and "t" if one of those is first letter. If you do want case-sensitivity then this version will only remove T not t

=REPLACE(A1,1,EXACT(LEFT(A1),"T")+0,"")

regards, barry
0
 
LVL 85

Accepted Solution

by:
Rory Archibald earned 500 total points
ID: 35068936
position = Worksheets("something").Cells(1, 1).Value

  if UCase(Left(position, 1)) = "T" then
      position = MID$(position, 2)
     Worksheets("something").Cells(1, 1).Value = position
end if  

Open in new window


for example.
0
 

Author Closing Comment

by:dmalovich
ID: 35068995
Awesome.  Thanks....
0
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 35069007
Since you didn't specify VBA in the original question, I think a points split would be more appropriate here?
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

687 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question