View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Gord Dibben Gord Dibben is offline
external usenet poster
 
Posts: 22,906
Default extracting numerics from literal strings

Ed

Programming method.

Sub Move_Nums()

Dim intI As Integer
Dim rngR As Range, rngRR As Range
Dim strNotNum As String, strTemp As String
Set rngRR = Selection.SpecialCells(xlCellTypeConstants, _
xlTextValues)
For Each rngR In rngRR
strTemp = ""
For intI = 1 To Len(rngR.Value)
If Mid(rngR.Value, intI, 1) Like "[0-9]" Then
strNotNum = Mid(rngR.Value, intI, 1)
Else: strNotNum = ""
End If
strTemp = strTemp & strNotNum
Next intI
rngR.Offset(0, 1).Value = strTemp
Next rngR
End Sub

Gord Dibben Excel MVP


On Sat, 7 Feb 2004 17:07:18 -0500, "Ed" wrote:

If my cell A1 contains a string such as "Total 30 employees", how do I
extract the value (e.g. 30) from this string and put it in cell B1?

Thanks.