Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I strip just numbers from an alphanumeric cell? Benjamin Excel Worksheet Functions 6 October 6th 09 12:36 AM
Alphanumeric Sorting - numeric alpha numeric Mike Excel Worksheet Functions 2 September 15th 08 10:12 PM
Obtain numeric from alphanumeric string Manj Excel Discussion (Misc queries) 3 March 14th 08 01:28 PM
Converting Alphanumeric numbers to Numeric Lowkey Excel Worksheet Functions 3 May 8th 06 11:24 PM
Strip Alpha Characters out of an Alphanumeric Dataset supersonicf111 Excel Programming 22 January 2nd 04 11:57 PM


All times are GMT +1. The time now is 04:45 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"