String - Condense or Expand

  • Each electronic components on electronics PCB has a reference designator (unique location). The reference designator usually consists of one or two letters followed by a number, e.g. R13, C1002.

    I'm trying to create a UDF that gets a string of locations and returns a group of consecutive locations as shown:

    Examples:

    1. C1, C2, C3 ==> C1-C3

    2. R4, R1, R7, R5, R3 ==> R1, R3-R4, R7

    3. LD100, LD101, LD102, LD103, LD104, LD105, LD107 ==> LD100-LD105, LD107

  • The file cannot be attached due to legal issues, however here is the file content in table format:


    Component Location Location (Short Form)
    COMP1 R1, R2, R4, R4, R5, R6, R7, R8, R9, R10 R1-R10
    COMP2 C98, C99, C103, C104, C105, C109, C11, C111, C115, C116, C117, C121 C98-C99, C103-C105, C115-C117, C121-C125, C129-C130
    COMP3 U2, U6, U12, U13 U2, U6, U12-U13
    COMP4
  • Hello jonny,


    Quite an interesting question ...;)


    Do you currently have a draft UDF you could post ... or should this UDF be built from scratch ...

    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Smiley" icon, below, in the bottom right corner :)

  • Hello again,


    Drafted an initial UDF ...


    Hope this will help

    :)

    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Smiley" icon, below, in the bottom right corner :)

  • Thanks for your feedback ... :)

    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Smiley" icon, below, in the bottom right corner :)

  • Sorry, Carim, just saw your code. Thank you.

    Don't know why , but somehow I'm not getting notifications once the answer is posted.


    Anyway the code is not grouping consecutive locations. By applying a code on U2, U6, U12, U13 I've gotten U12, U13, U2, U6.

    Where the expected result is U2, U6, U12-U13

  • Hello jonny,


    Thanks for your feedback ...


    Have not started working on the grouping ...


    My question was : Do you currently have a draft UDF you could post ... or should this UDF be completely built from scratch ...

    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Smiley" icon, below, in the bottom right corner :)

  • OK ... Thanks ...


    It is a bit of a challenge ... since there are quite a number of different steps to cover ...


    Extract prefix, Split, Sort, Group, Insert dashes, Join ... and Clean


    So this will require some time and efforts ...8o

    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Smiley" icon, below, in the bottom right corner :)

  • Hello jonny,


    Regarding your UDF to get the bins location in a short form ...


    attached is your test file ... BUT now ... I have to get myself some more aspirin 8o


    Hope this will help

    :)

  • Once you have had a chance to test the UDF ... feel free to share your comments ...

    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Smiley" icon, below, in the bottom right corner :)

  • Hi Jonny,


    Glad to hear this could help you out ...


    Thanks a lot for your very kind words ...:)

    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Smiley" icon, below, in the bottom right corner :)

  • MANY MANY THANKS ... for your Avalanche of THANKS ...:):):)

    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Smiley" icon, below, in the bottom right corner :)

  • To Future Forum Readers


    By coincidence, just stumbled upon the Exact Reverse situation with a blog post designed by Smallman

    with UDF called Sequence :


    Create Number Sequence with VBA Custom Function — Excel Dashboards VBA
    An Excel custom function that allows sequental number sequences to be created.
    www.thesmallman.com


    for example: How to list all numbers between : 100-117


    Hope this could assist :)

    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Smiley" icon, below, in the bottom right corner :)

  • Carim

    Changed the title of the thread from “Components Reference Designators” to “String - Condense or Expand”.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!