Solved

Show only the numbers in a cell

Posted on 2011-03-22
4
511 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Excel VBA - UserForm control click 12 35
Help with Journey Roadmap Graphic 11 48
EXCEL Addin problem 7 24
TT Column Arrange 10 28
Drop Down List with Unique/Distinct Values (enhancing the Combo-Box with a few steps and a little code) David miller (dlmille) Intro Have you ever created a data validation list from a database field or spreadsheet column (e.g., Zip Codes or Co…
Approximate matching with VLOOKUP and MATCH seems to me to be a greatly under-used technique, and one which is vital for getting good performance out of large lookups. Until recently I would always have advised using an exact match for simplicity an…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

706 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now