Formula to remove all but the last of the same character in a cell

James01

Board Regular
Joined
Oct 29, 2008
Messages
124
Hi

I have data in cell A1 and A2 which looks like below

SECTOR - 11, HIRAN MAGRI, - 313001
MAIN BRANCH, 30-15-171 DABA GARDENS, NEAR SARASWATI PARK,-530020,

In cell A1 the number of hypens (-) are 2
In cell A2 the number of - are 3

What I am looking for is a formula which can remove all additional - except the last one. Therefore the result of the formula should be

SECTOR 11, HIRAN MAGRI, - 313001
MAIN BRANCH, 30 15 171 DABA GARDENS, NEAR SARASWATI PARK,-530020

Is this possible by using a formula

Thanks for the replies
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Hi

Well on the other hand if from the whole list I want to identify the cell which do end with 6 digits, what formula should I use.

Thanks
 
Upvote 0
Here's a working solution. There may be a shorter one, but this should work:
Excel Workbook
AB
1SECTOR - 11, HIRAN MAGRI, - 313001TRUE
2MAIN BRANCH, 30-15-171 DABA GARDENS, NEAR SARASWATI PARK,-530020,FALSE
3MAIN BRANCH, 30-15-171 DABA GARDENS, NEAR SARASWATI PARK,-53000,FALSE
4MAIN BRANCH, 30-15-171 DABA GARDENS, NEAR SARASWATI PARK,-5300200,FALSE
5MAIN BRANCH, 30-15-171 DABA GARDENS, NEAR SARASWATI PARK,-5300200FALSE
6MAIN BRANCH, 30-15-171 DABA GARDENS, NEAR SARASWATI PARK,-53000FALSE
7MAIN BRANCH, 30-15-171 DABA GARDENS, NEAR SARASWATI PARK,-530020TRUE
Sheet1
Excel 2007
Cell Formulas
RangeFormula
B1=AND(ISNUMBER(VALUE(RIGHT(SUBSTITUTE(A1,"-","§"),6))),NOT(ISNUMBER(VALUE(MID(A1,LEN(A1)-6,1)))))
B2=AND(ISNUMBER(VALUE(RIGHT(SUBSTITUTE(A2,"-","§"),6))),NOT(ISNUMBER(VALUE(MID(A2,LEN(A2)-6,1)))))
B3=AND(ISNUMBER(VALUE(RIGHT(SUBSTITUTE(A3,"-","§"),6))),NOT(ISNUMBER(VALUE(MID(A3,LEN(A3)-6,1)))))
B4=AND(ISNUMBER(VALUE(RIGHT(SUBSTITUTE(A4,"-","§"),6))),NOT(ISNUMBER(VALUE(MID(A4,LEN(A4)-6,1)))))
B5=AND(ISNUMBER(VALUE(RIGHT(SUBSTITUTE(A5,"-","§"),6))),NOT(ISNUMBER(VALUE(MID(A5,LEN(A5)-6,1)))))
B6=AND(ISNUMBER(VALUE(RIGHT(SUBSTITUTE(A6,"-","§"),6))),NOT(ISNUMBER(VALUE(MID(A6,LEN(A6)-6,1)))))
B7=AND(ISNUMBER(VALUE(RIGHT(SUBSTITUTE(A7,"-","§"),6))),NOT(ISNUMBER(VALUE(MID(A7,LEN(A7)-6,1)))))
 
Upvote 0

Forum statistics

Threads
1,223,869
Messages
6,175,087
Members
452,611
Latest member
bls2024

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top