![]() |
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 |
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/ |
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/ |
All times are GMT +1. The time now is 10:16 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com