+ Reply to Thread
Results 1 to 19 of 19

Extract a mainly numeric string (ISSN number) from an arbitrary string

  1. #1
    Registered User
    Join Date
    02-04-2012
    Location
    CA, USA
    MS-Off Ver
    Excel 2010
    Posts
    56

    Extract a mainly numeric string (ISSN number) from an arbitrary string

    First post, really stumped here.

    I want to extract the ISSN (publication serial number) from an arbitrary string.

    The ISSN may exist in any of 4 formats:
    12345678 - 8 consecutive numbers
    1234-5678 - 8 numbers, middle dash i.e. between 4th & 5th digit
    1234567X - 7 consecutive numbers, X suffix
    1234-567X - 7 numbers, middle dash, X suffix

    All other cases should be ignored.
    For example:
    1234567
    123456789
    123-45678
    1234-56789
    123456X7

    My limited Excel skills would probably require a bunch of helper columns, so I'm looking for a cleaner approach, preferably with regular formulas.

    If there's a big difference in complexity between a reliable method vs. something that usually works, I'd prefer collecting false positives vs. missing valid ISSNs.

    Any comments appreciated.
    Last edited by Buzzed Aldrin; 02-12-2012 at 07:04 PM.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Extract a mainly numeric string from an arbitrary string

    Hello Buzzed Aldrin,

    Welcome to the Forum!

    While it may be possible to do what you want with formulas and helper columns, it would be very messy and inefficient. If these values aren't constantly changing then a UDF would be a much better solution. The best would be a VBA macro that would extract all the values with the push of a single button. Is there some reason that is preventing you from seeking a VBA solution?

    UDF to Return the ISSN from a String
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    02-04-2012
    Location
    CA, USA
    MS-Off Ver
    Excel 2010
    Posts
    56

    Re: Extract a mainly numeric string from an arbitrary string

    Is there some reason that is preventing you from seeking a VBA solution?
    Only because I've never had applications requiring anything more than simple formulas, therefore never used VBA macros.

    If VBA is the way to go here, then so be it... but I don't even know where to start. Where do I paste your code, and then what?

  4. #4
    Valued Forum Contributor AlvaroSiza's Avatar
    Join Date
    09-19-2007
    Location
    Staffordshire
    MS-Off Ver
    2007
    Posts
    591

    Re: Extract a mainly numeric string from an arbitrary string

    1. Open up the Visual Basic Editor (Alt + F11)
    2. Click Insert >> Module
    3. Copy and Paste the code Leith provided into Module 1 (which will appear after completing step 2)
    4. Save and close the Visual Basic Editor

    Now GETISSN is available as a function (a user-defined function, or "UDF") anywhere in this workbook; just like all of the other formulas/functions you are used to (=SUM, =Average, etc.).

    If an ISSN you wish to analyze is in, say, Cell A1, you would enter =GETISSN(A1) and the result will appear.

  5. #5
    Registered User
    Join Date
    02-04-2012
    Location
    CA, USA
    MS-Off Ver
    Excel 2010
    Posts
    56

    Re: Extract a mainly numeric string from an arbitrary string

    @Leith - Works beautifully for all cases except ISSNs having trailing characters (returns blank) which, unfortunately, I have a lot of. Can the code be modified to handle ISSNs amidst both leading and trailing text?

    @AlvaroSiza - Clear and straightforward, thank you!

  6. #6
    Registered User
    Join Date
    02-04-2012
    Location
    CA, USA
    MS-Off Ver
    Excel 2010
    Posts
    56

    Re: Extract a mainly numeric string from an arbitrary string

    Removing the "/b" portions per OnErrorGoto0's suggestion handles ISSNs with leading & trailing text, but I should have stated it needs to consider trailing numbers as well.

    I have strings that include long (>8 digit) numbers so the code erroneously considers the first 8 numbers encountered as an ISSN, so it needs to check for a 9th number and if it exists, reject the 9 numbers plus all consecutive numbers after it, i.e. reject the entire numeric block of the string.

    Can the code be mod'd to reject any 9+ digit number?

    Numbers after the other cases (7X, 4-4, 4-3X) are too unlikely so I won't worry about them.

  7. #7
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Extract a mainly numeric string from an arbitrary string

    Please test this version
    Please Login or Register  to view this content.
    Good luck.

  8. #8
    Registered User
    Join Date
    02-04-2012
    Location
    CA, USA
    MS-Off Ver
    Excel 2010
    Posts
    56

    Re: Extract a mainly numeric string from an arbitrary string

    Sorry for being away.
    I had to reformat my HD and am in the frustrating process of "rebuilding" my pc.
    Will get back asap.

  9. #9
    Registered User
    Join Date
    02-04-2012
    Location
    CA, USA
    MS-Off Ver
    Excel 2010
    Posts
    56

    Re: Extract a mainly numeric string from an arbitrary string

    @OEG0 - The latest version correctly rejects non-ISSN cases, but now it's including an extra character before and after a valid ISSN.

    For example, for ABC1234-5678XYZ the code returns C1234-5678X

    The code looks simple but because my VBA skill is zero I don't want to risk messing it up. Can you tweak it to avoid the first and last character while preserving the current ability to reject non-ISSNs?

  10. #10
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Extract a mainly numeric string from an arbitrary string

    Try this one
    Please Login or Register  to view this content.

  11. #11
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Extract a mainly numeric string from an arbitrary string

    As Leith said this can be done using formulae, but it might be considered messy.

    Just for fun try this workbook ...

    Using helper columns
    1/. Column B - Extract the first number from the string.
    2/. Use as many columns you need to return your conditions. In this example Columns C:F.
    3/. In the next column, in this example Column G, collate the result.
    4/. Use a grouping button on, or hide, Columns B:F
    Attached Files Attached Files
    If you need any more information, please feel free to ask.

    However,If this takes care of your needs, please select Thread Tools from menu above and set this topic to SOLVED. It helps everybody! ....

    Also
    اس کی مدد کرتا ہے اگر
    شکریہ کہنے کے لئے سٹار کلک کریں
    If you are satisfied by any members response to your problem please consider using the small Star icon bottom left of their post to show your appreciation.

  12. #12
    Registered User
    Join Date
    02-04-2012
    Location
    CA, USA
    MS-Off Ver
    Excel 2010
    Posts
    56

    Re: Extract a mainly numeric string from an arbitrary string

    @ OEG0 - I'm getting a #VALUE! error on the latest code.

    @ Marcol - I've only glanced at it, but it appears to handle every valid case while rejecting every invalid one, very nice. My version has about 20 helper columns

  13. #13
    Registered User
    Join Date
    02-04-2012
    Location
    CA, USA
    MS-Off Ver
    Excel 2010
    Posts
    56

    Re: Extract a mainly numeric string (ISSN number) from an arbitrary string

    @ OEG0 - Never mind! Gosh I don't know why I even mentioned the extra first/last character; it's trivial for me to just lop them off with a formula.

    Thanks all, this one's solved.

  14. #14
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Extract a mainly numeric string (ISSN number) from an arbitrary string

    You could if you wish reduce the number of helpers, I only left them in for clarity.
    However with 2003 you will not get them down to say 2 with these formulae because of nesting limitations.

    See Sheet2 in this workbook.
    Attached Files Attached Files

  15. #15
    Registered User
    Join Date
    02-04-2012
    Location
    CA, USA
    MS-Off Ver
    Excel 2010
    Posts
    56

    Re: Extract a mainly numeric string (ISSN number) from an arbitrary string

    You could if you wish reduce the number of helpers, I only left them in for clarity.
    However with 2003 you will not get them down to say 2 with these formulae because of nesting limitations.
    I have '03 and it seems to work.
    It's for my own use so either version is fine, thx again.

  16. #16
    Registered User
    Join Date
    02-04-2012
    Location
    CA, USA
    MS-Off Ver
    Excel 2010
    Posts
    56

    Re: Extract a mainly numeric string (ISSN number) from an arbitrary string

    Could someone modify the most recent UDF to also handle a lowercase "x" ?

  17. #17
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Extract a mainly numeric string (ISSN number) from an arbitrary string

    Hello Buzzed Aldrin,

    This version will handle it.
    Please Login or Register  to view this content.

  18. #18
    Registered User
    Join Date
    02-04-2012
    Location
    CA, USA
    MS-Off Ver
    Excel 2010
    Posts
    56

    Re: Extract a mainly numeric string (ISSN number) from an arbitrary string

    Thank you Leith !

  19. #19
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Extract a mainly numeric string (ISSN number) from an arbitrary string

    Hello Buzzed,

    I was wondering if you would come back and check this thread. You're welcome.

+ 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