Thursday, November 20, 2014

worksheet function - remove three digits based on condition in excel?


I have a sheet with data , i want to remove last three numbers , but in some cells i have text only so i need a formula that remove last three numbers if cell have, For Ex:


Cell A                     |    Cell B
---------------------------------------------
my data row 1 in 123 | my data row 1 in
----------------------------------------------
this is 2nd row data in 345| this is 2nd row data in
----------------------------------------------
3rd row data | 3rd row data

I tried this code =LEFT(F2,LEN(F2)-3)&"" and its work if cell have numbers but problem is their when column have no numbers in last this formula remove 3 words from text. so i need formula that remove only last 3 numbers if cell have, otherwise print data as it as in next column , hope understand my question thanks.


Answer



You can check whether last three characters are numbers, and remove them only if yes:


=IF(ISERROR(VALUE(RIGHT(A1,3))),A1,LEFT(A1,LEN(A1)-3))


enter image description here


No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...