Home |
Search |
Today's Posts |
#5
![]()
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
![]()
Remove all but numbers using UDF
Function RemAlpha(str As String) As String 'Remove Alphas from a string Dim re As Object Set re = CreateObject("vbscript.regexp") re.Global = True re.Pattern = "\D" RemAlpha = re.Replace(str, "") End Function Macro to do in place. Sub RemoveAlphas() ' Remove alpha characters from a string. 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.Value = strTemp Next rngR End Sub Gord Dibben MS Excel MVP On Mon, 8 Jun 2009 05:40:01 -0700, don wonnell wrote: Have Excel 2002, want to remove text from cells and leave the numerical data in those cells intact. Don't see a method for this in worksheet functions listed by category / text & data. |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Removing Text | Excel Discussion (Misc queries) | |||
Removing text from a cell with text and numbers | Excel Discussion (Misc queries) | |||
Removing text | Excel Discussion (Misc queries) | |||
question about removing text from cells, leaving numbers | Excel Discussion (Misc queries) |