excel - insert space automatically with formula

JSH720

Board Regular
Joined
Oct 9, 2009
Messages
109
Office Version
  1. 365
Platform
  1. Windows
I have a string that looks like this:
10N23w05
I need it to look like this 10N 23W 05

In other words, with a space where indicated. Further complicated by the fact that some of the 50000 instances already have a space. they don't need another space entered. Is there a custom format,or formula or something else that can be set up. I'm not allowed to use macros.

Thanks.
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Will all the entries EXACTLY follow the format of:
3 characters + 1 space + 3 characters + 1 space + 2 characters?

If so, try this formula (written for an entry in cell A1):
Code:
=IF(LEN(TRIM(A1))=8,LEFT(A1,3) & " " & MID(A1,4,3) & " " & MID(A1,7,2),A1)
 
Upvote 0
=REPLACE(REPLACE(A1,4,," "),8,," ")
Marcelo,
That doesn't quite seem to work for entries that already have spaces in them. It seems to double them up.
 
Upvote 0
Marcelo,
That doesn't quite seem to work for entries that already have spaces in them. It seems to double them up.

Oh, you're right

What about
=REPLACE(REPLACE(SUBSTITUTE(A1," ",""),4,," "),8,," ")

M.
 
Upvote 0
What about
=REPLACE(REPLACE(SUBSTITUTE(A1," ",""),4,," "),8,," ")
That seems to work correctly.
 
Upvote 0
If the numbers can have other than 2 digits, then maybe:

=TRIM(SUBSTITUTE(SUBSTITUTE(UPPER(A1),"N","N "),"W","W "))

and if the N and W represent North and West, then this can handle S and E:

=TRIM(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(UPPER(A1),"N","N "),"S","S "),"E","E "),"W","W "))
 
Upvote 0
If the numbers can have other than 2 digits, then maybe:

=TRIM(SUBSTITUTE(SUBSTITUTE(UPPER(A1),"N","N "),"W","W "))

and if the N and W represent North and West, then this can handle S and E:

=TRIM(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(UPPER(A1),"N","N "),"S","S "),"E","E "),"W","W "))

Will they ever come up with a SUBSTITUTE function that takes away the need to nest 4 substitutes? like having optional 2nd and 3rd arguments??

i just searched uservoice, and it has this suggestion, but i thought it would be more popular.. :(
https://excel.uservoice.com/forums/...-substitute-text-old-text1-old-text2-new-text
 
Upvote 0
My apologies. This went to my spam folder and I just saw it. Yes they all will follow that exact format, it worked thank you! and may your new year and the years to follow be filled with fun and health!
 
Upvote 0
You are welcome.
Glad we were able to help!
:)
 
Upvote 0

Forum statistics

Threads
1,223,704
Messages
6,173,984
Members
452,540
Latest member
haasro02

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