INSERT A SPACE INTO A TEXT VALUE

JonRowland

Active Member
Joined
May 9, 2003
Messages
416
Office Version
  1. 365
Platform
  1. Windows
Hi,

Hope someone can help me.

I have a number of text values. However, I need to be able to add a space into these after the fifth character.

Any ideas how I can do this?

Thanks

Jon
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Same type of question, however, I need to add . back into a column of email address that were incorrectly changed to have the . removed
Give this a try...
Code:
Function InsertDots(S As String) As String
  Dim X As Long
  InsertDots = S
  For X = Len(InsertDots) To 2 Step -1
    If (Mid(InsertDots, X - 1, 1) Like "#" And Mid(InsertDots, X, 1) Like "[A-Za-z]") Or _
       (Mid(InsertDots, X - 1, 1) Like "[A-Za-z]" And Mid(InsertDots, X, 1) Like "#") Then
      InsertDots = WorksheetFunction.Replace(InsertDots, X, 0, ".")
    End If
  Next
End Function
 
Upvote 0
Try something along these lines
Code:
Function NumB(k$) As Boolean    ' is it a number character
    NumB = k >= "0" And k <= "9"
End Function
Private Sub CommandButton1_Click()
    'use like
    Range("d3") = DotIt(Range("d2"))
End Sub
Function DotIt$(w$) ' to dot on change of character type
    Dim WA$, Numeric As Boolean, CC%
    'set the first character
    WA = Left(w, 1)
    Numeric = NumB(WA)
    'work through the characters
    For CC = 2 To Len(w)
        If Numeric <> NumB(Mid(w, CC, 1)) Then WA = WA + "."    ' changed
        'deal with character
        Numeric = NumB(Mid(w, CC, 1))
        WA = WA + Mid(w, CC, 1)
    Next CC
    DotIt = WA
End Function
 
Upvote 0
I did not see Rick's excellent post when I first visited.. so it is a repeat solution ( again )
Good to see a 2004 thread still surviving and drawing interest
the extra function Numb used so that it can further define the conditions of the change
without too much changing .
That is what is wanted from as string like
vcxxdfvsd56221 23 dsfsdfd safddsfdasf 2354 fdfas as34324#$$%&)()_))(*(()_)<> fvsdf
where the characters about the space remain the same or change, what of multiple spaces
dsfd 3432423 43435gerdg 545565%^^&**(()
what about we do not complicate it too much.. time for breakfast in Aus.
 
Last edited:
Upvote 0
Hi Guys, Thanks for the post. I'm also trying to add a space in a text string. In my case I'd like to add a space between the "y" and "2" in "Games Barney20171027 $1250". I tried modifying the reply from the this thread =LEFT(M5,13)&" "&RIGHT(M5,LEN(M5)-14) but my text displays as
Games Barney 0171027 $1250. Any suggestions on why my 2 is dropping out of my year 2017?

<tbody>
</tbody>

<tbody>
</tbody>
 
Upvote 0
Try:
=LEFT(A1,12)&" "&RIGHT(A1,LEN(A1)-12)
 
Upvote 0
Hi Mumps, I tweeked your post to fit my spreadsheet and produced Games Barney 20171027 $1250
by using =LEFT(M5,12)&" "&RIGHT(M5,LEN(M5)-12). But I think it's wrong, when I copy it down, my spaces are absolute and the next line looks like Music David2 0171020 $1054, putting a space in the wrong place, any suggestions?
 
Upvote 0
How about:

=TRIM(REPLACE(A1,MIN(SEARCH({0,1,2,3,4,5,6,7,8,9},A1&"0123456789")),0," "))
 
Upvote 0
Hi,

This will also work if all your years start with 20xx:


Book1
MN
5Games Barney20171027 $1250Games Barney 20171027 $1250
6Music David20171020 $1054Music David 20171020 $1054
7Something20171112 $9999Something 20171112 $9999
8Some Other Thing20170204 $1111Some Other Thing 20170204 $1111
Sheet32
Cell Formulas
RangeFormula
N5=REPLACE(M5,FIND("20",M5),0," ")
 
Upvote 0
I bow down to you Excel master fish. That worked out great. I copied it down 500 rows putting a space exactly where I needed it.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,019
Messages
6,122,707
Members
449,093
Latest member
Mnur

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