View Single Post
  #11   Report Post  
Posted to microsoft.public.excel.misc
peyman peyman is offline
external usenet poster
 
Posts: 189
Default pulling out Numbers

hi Mike,
the problem is , it removes the zero at the begining of a numbers after
pulling out them,like:
aab0125 turns to 125 instead of 0125

"Mike H" wrote:

Another way.

I'm a bit cofused why the previous method only removed th dash but try this

Sub anotherway()
For Each cell In Selection
For a = 1 To Len(cell)
Select Case Mid(cell, a, 1)
Case "0" To "9"
newstring = newstring & Mid(cell, a, 1)
End Select
Next a
cell.Value = newstring
ActiveCell.NumberFormat = "General"
newstring = ""
Next cell
End Sub

Mike

"peyman" wrote:

hi Mike,
it just removes dash "-" from string!! not letters.

"Mike H" wrote:

With a macro:-

Sub removeletters()
For Each cell In Selection
For a = 1 To Len(cell)
If Asc(Mid(cell, a, 1)) 47 And Asc(Mid(cell, a, 1)) < 59 Or _
Asc(Mid(cell, a, 1)) 64 And Asc(Mid(cell, a, 1)) < 91 Then _
newstring = newstring & Mid(cell, a, 1)
Next
cell.Value = newstring
ActiveCell.NumberFormat = "General"
newstring = ""
Next
End Sub

Select the cells to convert and run this

Mike

"peyman" wrote:

hi,
how can I pull out numbers from a string?like:
aa012985 to 012985
12ab-059 to 12059
the letters or characters might be either at the first, middle or at the end
of a string.
thanx in advance.