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
Solved

Show only the numbers in a cell

Posted on 2011-03-22
4
515 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
  • 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Drop Down List with Unique/Distinct Values (Part II - ComboBox or ListBox and Data Validation List Bonus!) David Miller (dlmille) Intro This article focuses on delivering unique, sorted lists to list objects (e.g., ComboBox, ListBox) and Dat…
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

839 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