Beatiful piece of code. It works like a charm. As I'm still learning and want to get better, can I leave some comments inside the code in terms of how I understand it. Am I more or less understanding it correctly?
Sub r4u()
Dim r As Range
Dim cell As Range
Dim i As Long
Dim sInp As String
Dim sOut As String
On Error Resume Next
'---vvv---------------Sets the range i.e. currently selected range, only the cells that contain text
Set r = ActiveWindow.RangeSelection.SpecialCells(xlCellTypeConstants, xlTextValues)
'---vvv---------------if cell contains text then
If Not r Is Nothing Then
For Each cell In r
'---vvv---------------gets the string value from cell
sInp = cell.Value
'---vvv---------------sets the string sOut value to blank
sOut = ""
'---vvv---------------gets the number of characters in a particular string and then starts to loop through each character
For i = 1 To Len(sInp)
'---vvv---------------embarrasing to say but I'm not really familiar how "select Case" works. After all these years I stil have not learned to use case
'But effectivelly it loops through all the characteres within the original string
Select Case Mid(sInp, i, 1)
'---vvv---------------if the character is between number 0 - 9 or "." then the code ads these characters to our new string
' Other characters simply get ignored and wont be part of the new string.
Case "0" To "9", "."
sOut = sOut & Mid(sInp, i, 1)
End Select
Next i
'---vvv-----------------end result
cell.Value = sOut
Next cell
End If
End Sub
Bookmarks