+ Reply to Thread
Results 1 to 14 of 14

Converting strings to unique number pattern

  1. #1
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,946

    Converting strings to unique number pattern

    Hi Guys,

    I have difficult task to do.

    i have a table where i have column like Name and values assigned:
    Paul, Luke, Jacek, Michel, Paul, Luke (yes it can repeat).

    What i want is to use VBA to create digit patterns from them (max to 10 digits allowed).
    I mean like 123, 555, 112, 999, 123, 555.

    So the same digit pattern for the same string. I will have different lengths of strings but what is important,
    I have to use generally 18 columns to convert them to unique numbers, concatenate all fields and create Key column and not exceed more than 255 characters.
    I do not have to use digits as pattern, it can be special signs or whatever, should be unique.

    It is possible at all?

    Thank you for help,
    Best wishes,
    Jacek
    Last edited by jaryszek; 02-08-2019 at 03:50 AM.

  2. #2
    Forum Expert kersplash's Avatar
    Join Date
    11-22-2016
    Location
    Perth
    MS-Off Ver
    Home 2016 (Windows 10)/Work 2013 Pro Plus (Windows 10)
    Posts
    2,012

    Re: Converting strings to unique number pattern

    Can you attach a sample of your source data and what you expect your output to look like?

  3. #3
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,946

    Re: Converting strings to unique number pattern

    Hi kerplash,

    i would like to attach a sample but this is more theoretical question than sample, i do not have sample.

    How to show unique string or number if it can be a concatenation of special signs or digits...

    Best,
    Jacek

  4. #4
    Forum Expert kersplash's Avatar
    Join Date
    11-22-2016
    Location
    Perth
    MS-Off Ver
    Home 2016 (Windows 10)/Work 2013 Pro Plus (Windows 10)
    Posts
    2,012

    Re: Converting strings to unique number pattern

    In theory I'd love to help you too.

  5. #5
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,946

    Re: Converting strings to unique number pattern

    Workbook added,

    Best,
    Jacek
    Attached Files Attached Files

  6. #6
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,946

    Re: Converting strings to unique number pattern

    What i am thinking maybe macro can check the longest string in a row and based on that set up number of special signs or digits (and remember to not exceed 255 characters).
    So when i will have 18 columns the longest string will have 15 signs and i can check that unique number for each string can be 237/18 (255 minus "-" x 18 for concatenated field) = 14, so i should create unique fields max length = 10 for example.

    Best,
    Jacek

  7. #7
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Converting strings to unique number pattern

    The easiest way to assign a unique number to the names in column A would be to use MATCH(A1, A:A, 0) which returns the first row on which that name appears.

    Your attached file doesn't have 18 columns, so I'm not sure what that refers to.

    Could you attach a file with an example input (with multiple columns) and the desired output?
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  8. #8
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,946

    Re: Converting strings to unique number pattern

    Hi mikerickson,

    thank you for getting involved,
    I added 18 columns and create Key field where concatenated string exceed 255 characters.
    If i would change each same string for unique characteristic signs or digits, i could not exceed 255 number.

    Best,
    Jacek
    Attached Files Attached Files

  9. #9
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,946

    Re: Converting strings to unique number pattern

    Hi Guys,

    what do you think about hashcodes, they can be useful in this case?

    Best,
    Jacek

  10. #10
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,946

    Re: Converting strings to unique number pattern

    Hello,

    anyone can help?

    Best wishes,
    thank you in advance,
    Jacek Antek

  11. #11
    Registered User
    Join Date
    02-05-2019
    Location
    Czech
    MS-Off Ver
    2016
    Posts
    24

    Re: Converting strings to unique number pattern

    Hi jaryszek,

    i love difficult topics so i did research and find great solution for you, try to use hash codes,

    try this code to convert string to hashcode:

    Please Login or Register  to view this content.
    So you can convert your each field in every row to hash code (using loop and arrays for examples), and after that joined all fields together in order to get key.
    Of course if you will use too small amount of signs there is a probability to get "collision" but using SHA1 + Base64 hash code (my favorite one) and keeping about 10 signs for field you are almost sure that your data will work without any issues and collision thing. Tested on 10 thousends rows.

    I do not think that there is other solution, maybe other people can help, but try mine ;-)

    Paul Ant

  12. #12
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,946

    Re: Converting strings to unique number pattern

    Hi Paul,

    thank you very much, wow this is i thing great solution.

    Thank you,
    i am not closing this topic because maybe other Excel Masters know better ways.

    Best,
    Jacek

  13. #13
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,946

    Re: Converting strings to unique number pattern

    hi Paul,

    i tested code and seems to work nice - maybe this is not speed demon but working.
    I do not think there is a possibility to do this better, you are awesome man!

    Thank you once again,
    Best,
    Jacek

  14. #14
    Registered User
    Join Date
    02-05-2019
    Location
    Czech
    MS-Off Ver
    2016
    Posts
    24

    Re: Converting strings to unique number pattern

    Jacek,

    no problem, i am Expert here for you to help.
    Last edited by Paulant; 02-11-2019 at 04:17 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] remove character strings in a specific pattern..
    By mohit999 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 03-15-2018, 06:29 AM
  2. Find pattern matches in hundreds of thousands of strings - speeding it up.
    By JasperD in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-04-2017, 12:28 PM
  3. Positional pattern strings within pick 4 positions
    By jorel in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-02-2017, 08:04 PM
  4. [SOLVED] How can I trim strings with re-occurring pattern to a defined string
    By dschmitt in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-29-2015, 01:45 AM
  5. Using the .Pattern Method for identifying Strings
    By jordan2322 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-13-2013, 07:20 PM
  6. Replies: 3
    Last Post: 11-12-2012, 01:52 PM
  7. Replies: 5
    Last Post: 02-15-2012, 09:57 AM

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