+ Reply to Thread
Results 1 to 12 of 12

Separate text from numbers

Hybrid View

legolas Separate text from numbers 02-09-2010, 08:53 AM
martindwilson Re: serperate text from... 02-09-2010, 09:35 AM
JBeaucaire Re: separate text from numbers 02-09-2010, 12:49 PM
legolas Re: separate text from numbers 02-09-2010, 03:07 PM
JBeaucaire Re: separate text from numbers 02-09-2010, 03:10 PM
legolas Re: separate text from numbers 02-10-2010, 02:22 AM
DonkeyOte Re: Separate text from numbers 02-10-2010, 02:55 AM
JBeaucaire Re: Separate text from numbers 02-10-2010, 03:05 AM
legolas Re: Separate text from numbers 02-10-2010, 08:51 AM
martindwilson Re: Separate text from numbers 02-10-2010, 09:39 AM
legolas Re: Separate text from numbers 02-11-2010, 08:58 AM
DonkeyOte Re: Separate text from numbers 02-11-2010, 09:15 AM
  1. #1
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Separate text from numbers

    FWIW - if you opted for UDF - Regular Expressions may be worth considering...

    Function NumberExtract(rngString As Range, Optional lngInstance As Long = 1) As Variant
    Dim RegExp As Object, RegExpMatch As Object
    On Error Resume Next
    Set RegExp = CreateObject("vbscript.regexp")
    With RegExp
        .Global = True
        .IgnoreCase = True
        .Pattern = "[0-9]+"
    End With
    Set RegExpMatch = RegExp.Execute(rngString)
    If lngInstance > RegExpMatch.Count Then
        NumberExtract = ""
    Else
        NumberExtract = RegExpMatch(lngInstance - 1)
    End If
    Set RegExpMatch = Nothing
    Set RegExp = Nothing
    End Function

    Assume string in A1, numbers to go in B1, C1 etc...

    B1: =NUMBEREXTRACT($A1,COLUMNS($B1:B1))
    copied across

    The second variable is optional - ie should you only be looking to return a single numeric value (first) it could be omitted - in this case we increment the value to return 1st, 2nd, 3rd etc...

    Not very effiicient though doing this with functions though IMO...a sub routine would be better.

    EDIT:

    if you want the output for finds to be numeric adjust the 2nd NumberExtract line to:

    NumberExtract = Val(RegExpMatch(lngInstance - 1))
    Last edited by DonkeyOte; 02-11-2010 at 09:18 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1