Results 1 to 10 of 10

Thread: Extract Only Numbers & TEXT From Text String

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Forum Guru Rick Rothstein's Avatar
    Join Date
    Feb 2012
    Posts
    662
    Rep Power
    15
    Quote Originally Posted by mahmoud-lee View Post
    Thank you mr admin , This formula is not working after the seventh condition
    That is because you are using XL2003 which has a limit of 7 nested function calls (this limit was lifted in XL2007 and above). How about two UDFs (User Defined Functions)...

    Code:
    Function DigitsOnly(ByVal s As String) As Variant
      Dim X As Long
      For X = 1 To Len(s)
        If Mid(s, X, 1) Like "[!0-9]" Then Mid(s, X, 1) = Chr(1)
      Next
      DigitsOnly = Replace(s, Chr(1), "")
      If Len(DigitsOnly) < 16 Then DigitsOnly = Val(DigitsOnly)
    End Function
    
    Function NoDigits(ByVal s As String) As String
      Dim X As Long
      For X = 1 To Len(s)
        If Mid(s, X, 1) Like "#" Then Mid(s, X, 1) = Chr(1)
      Next
      NoDigits = Trim(Replace(s, Chr(1), ""))
    End Function
    HOW TO INSTALL UDFs
    ------------------------------------
    If you are new to UDFs, they are easy to install and use. To install it, simply press ALT+F11 to go into the VB editor and, once there, click Insert/Module on its menu bar, then copy/paste the above code into the code window that just opened up. That's it.... you are done. You can now use NameOfTheUDF just like it was a built-in Excel function. For example, put the specified formula in the indicated cells...

    B3: =DigitsOnly(A3)

    C3: =NoDigits(A3)

    and then copy them down.
    Last edited by Rick Rothstein; 11-02-2013 at 07:47 AM.

Similar Threads

  1. Get Field from Delimited Text String
    By Rick Rothstein in forum Rick Rothstein's Corner
    Replies: 5
    Last Post: 07-25-2025, 08:35 AM
  2. Replies: 7
    Last Post: 08-29-2013, 12:01 PM
  3. Remove Special Characters From Text Or Remove Numbers From Text
    By Excel Fox in forum Excel and VBA Tips and Tricks
    Replies: 5
    Last Post: 05-31-2013, 04:43 PM
  4. Replies: 14
    Last Post: 05-25-2013, 06:55 AM
  5. Extract Certain Characters From A Text String
    By bobkap in forum Excel Help
    Replies: 5
    Last Post: 05-24-2013, 06:25 AM

Posting Permissions

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