Solved

Show only the numbers in a cell

Posted on 2011-03-22
4
517 Views
Last Modified: 2012-05-11
Hi,

I have a column that has data like the below. I need to strip the text and just leave the number. Its not standardised in any way. Meaning its in a random place in the each cell.

OvrE LB               GaQZB/EXANQ/305840570975     SAQ
GasdON G              292045400106             SVO


Thanks
0
Comment
Question by:andybrooke
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 8

Expert Comment

by:ragnarok89
ID: 35190932
0
 
LVL 19

Expert Comment

by:akoster
ID: 35190985
use
Sub process_contents()
    
    For Each cel In UsedRange.Cells
        contents = cel.Value
        '-- find first numeric
        For pos = 1 To Len(contents)
            If IsNumeric(Mid(contents, pos, 1)) Then
                contents = Mid(contents, pos)
                Exit For
            End If
        Next pos
        '-- find last numeric
        For pos = 1 To Len(contents)
            If Not IsNumeric(Mid(contents, pos, 1)) Then
                contents = Left(contents, pos - 1)
                Exit For
            End If
        Next pos
        
    Next cel


End Sub

Open in new window


as a start
0
 
LVL 24

Accepted Solution

by:
broomee9 earned 500 total points
ID: 35191083
Try this, it will remove all characters that are not numeric:
Option Explicit

Function RemoveAlpha(Rng As String) As String
    Dim Tmp As String
    Dim i As Integer
    Dim Alpha As String
    
    Tmp = Rng
    'Numbers are 48-57
    For i = 1 To 255
        If i >= 48 And i <= 57 Then GoTo skip
        Alpha = Chr(i)
        Tmp = Application.Substitute(Tmp, Alpha, "")
skip:
    Next i
    RemoveAlpha = Tmp
End Function

Open in new window

Book1.xls
0
 
LVL 24

Expert Comment

by:broomee9
ID: 35191104
To add a little explanation, the above is a UDF (User Defined Function) and you would enter it like any other function in Excel.  So if you're data is in A1, put this in B1:

=RemoveAlpha(A1)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question