Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
VBA - Looking to strip alphanumeric from numeric
Hi,
I am trying to write a VBA macro that given an input of, say "AS9F89A779FA87" will give an output of "98977987". The macro I want t write would analyze a given input with mixed alphanumeric and numeri characters, and remove the alphanumeric from the numeric. But I'm stuck....help please -- Message posted from http://www.ExcelForum.com |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
VBA - Looking to strip alphanumeric from numeric
Try something like the following:
Dim S As String Dim Pos As Long Dim Res As String S = "ABC123DEF456" For Pos = 1 To Len(S) If IsNumeric(Mid(S, Pos, 1)) = True Then Res = Res & Mid(S, Pos, 1) End If Next Pos MsgBox Res -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com "Dingo " wrote in message ... Hi, I am trying to write a VBA macro that given an input of, say, "AS9F89A779FA87" will give an output of "98977987". The macro I want to write would analyze a given input with mixed alphanumeric and numeric characters, and remove the alphanumeric from the numeric. But I'm stuck....help please! --- Message posted from http://www.ExcelForum.com/ |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
VBA - Looking to strip alphanumeric from numeric
Dingo
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 Excel MVP On Thu, 29 Jan 2004 19:50:47 -0600, Dingo wrote: Hi, I am trying to write a VBA macro that given an input of, say, "AS9F89A779FA87" will give an output of "98977987". The macro I want to write would analyze a given input with mixed alphanumeric and numeric characters, and remove the alphanumeric from the numeric. But I'm stuck....help please! --- Message posted from http://www.ExcelForum.com/ |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
How do I strip just numbers from an alphanumeric cell? | Excel Worksheet Functions | |||
Alphanumeric Sorting - numeric alpha numeric | Excel Worksheet Functions | |||
Obtain numeric from alphanumeric string | Excel Discussion (Misc queries) | |||
Converting Alphanumeric numbers to Numeric | Excel Worksheet Functions | |||
Strip Alpha Characters out of an Alphanumeric Dataset | Excel Programming |