Insert space after non-numeric character and a period

descher

New Member
Joined
Jul 25, 2014
Messages
2
Is there a way to check for a space between a non-number character, a period, and the next non-number character? In other words, I want to check text cells to make sure I don't have something like, "Attain the ridge line at 0.25 miles.Once there, head north."

I want Excel to find "miles.Once" but not "0.25." Then I want to insert a space so that it become "miles. Once"

It seems like I need to add a condition to a statement like this:

=TRIM(SUBSTITUTE(A2,".",". "))

Thank you in advance for your help.
Daniel
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
I am not sure there is a formula solution that only uses Excel functions possible for that; however, a UDF (user defined function) can be created to do it...
Code:
Function Periods(S As String) As String
  Dim X As Long, Parts() As String
  Parts = Split(S, ".")
  For X = 1 To UBound(Parts)
    If Left(Parts(X), 1) Like "[!0-9 ]" Then Parts(X) = " " & Parts(X)
  Next
  Periods = Join(Parts, ".")
End Function

HOW TO INSTALL UDFs
------------------------------------
If you are new to UDFs, they are easy to install and use. To install it, simply press ALT+F11 to go into the VB editor and, once there, click Insert/Module on its menu bar, then copy/paste the above code into the code window that just opened up. That's it.... you are done. You can now use Periods just like it was a built-in Excel function. For example,

=Periods(A1)

If you are using XL2007 or above, make sure you save your file as an "Excel Macro-Enabled Workbook (*.xlsm) and answer the "do you want to enable macros" question as "yes" or "OK" (depending on the button label for your version of Excel) the next time you open your workbook.
 
Upvote 0
Rick, thanks for your quick response! Unfortunately, I'm using Excel 2008 for Mac, so no VB capabilities to test it now. I'll try later on Windows.

Cheers.

I am not sure there is a formula solution that only uses Excel functions possible for that; however, a UDF (user defined function) can be created to do it...
Code:
Function Periods(S As String) As String
  Dim X As Long, Parts() As String
  Parts = Split(S, ".")
  For X = 1 To UBound(Parts)
    If Left(Parts(X), 1) Like "[!0-9 ]" Then Parts(X) = " " & Parts(X)
  Next
  Periods = Join(Parts, ".")
End Function

HOW TO INSTALL UDFs
------------------------------------
If you are new to UDFs, they are easy to install and use. To install it, simply press ALT+F11 to go into the VB editor and, once there, click Insert/Module on its menu bar, then copy/paste the above code into the code window that just opened up. That's it.... you are done. You can now use Periods just like it was a built-in Excel function. For example,

=Periods(A1)

If you are using XL2007 or above, make sure you save your file as an "Excel Macro-Enabled Workbook (*.xlsm) and answer the "do you want to enable macros" question as "yes" or "OK" (depending on the button label for your version of Excel) the next time you open your workbook.
 
Upvote 0
Are you expecting many mistakes of that kind? If yes, pre-spellcheck automatic correcting may be very useful and time-saving.
If no, finding and correcting these mistakes may be considered to be delayed until spell checking (Review/Spelling), which you will probably perform in any case if longer texts are involved (of course, then only one by one). In addition, spell checkers can handle special cases, e.g. „gmail@pet.com” , „a.m.”, „e.g” etc. or at least stops at the problematic words.
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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