+ Reply to Thread
Results 1 to 5 of 5

Find common starting string in all rows in column

  1. #1
    Registered User
    Join Date
    03-24-2020
    Location
    Maryland
    MS-Off Ver
    365
    Posts
    7

    Find common starting string in all rows in column

    Hi everyone,

    I'm working on a VBA script, and part of it requires renaming potentially up to 40 names. The way the data is originally exported will be consistent between each row in any given dataset, but not between datasets. I am looking for a VBA code that will look at all strings in A1:A41, and return the starting common string.

    For example, dataset 1 may be
    A1: Demo a_b 2021.05.19 - Mark - Monday
    A2: Demo a_b 2021.05.19 - Jared - Tuesday
    A3: Demo a_b 2021.05.19 - Patty - Thursday
    A4 - A41 same pattern

    and dataset 2 may be
    A1: Demo a_b 2021.05.20 - Mark - Monday
    A2: Demo a_b 2021.05.20 - Jared - Tuesday
    A3: Demo a_b 2021.05.20 - Patty - Thursday
    A4 - A41 same pattern

    So as you can see, each time the data is analyzed, the first part is consistent within that dataset, but the second part changes. I am looking for a code that will search A1:A41 and return as much of the string from the left that matches every cell.

    The ultimate goal is the return a prompt which says "All of your samples start with XXX, would you like me to remove this from their names?"
    Attached Files Attached Files
    Last edited by stranula; 05-19-2021 at 04:55 PM.

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2406 Win 11 Home 64 Bit
    Posts
    24,035

    Re: Find common starting string in all rows in column

    Fast answers need visual help. Please read the yellow banner at the top of this page on how to attach a file.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Registered User
    Join Date
    03-24-2020
    Location
    Maryland
    MS-Off Ver
    365
    Posts
    7

    Re: Find common starting string in all rows in column

    Hi, I've attached an excel file with the example strings in it. Thanks!

  4. #4
    Forum Contributor
    Join Date
    05-09-2021
    Location
    Sweden
    MS-Off Ver
    Office 365
    Posts
    148

    Re: Find common starting string in all rows in column

    Hello stranula,

    Important when you put your examples that they are realistic.

    Assuming that they are, it means that you already know where to find the common starting string. It is always the 19 first characters. Then you could do it like this...

    Please Login or Register  to view this content.
    Or even more simple, with a formula somewhere on your sheet.
    Please Login or Register  to view this content.
    Assuming that your examples are not realistic and that the common starting string could vary in length between datasets, then something like this could work (I am sure someone here could do it better, but it works )
    Please Login or Register  to view this content.
    Let us know if this helped you or if you need something else.

    Good luck!

  5. #5
    Registered User
    Join Date
    03-24-2020
    Location
    Maryland
    MS-Off Ver
    365
    Posts
    7

    Re: Find common starting string in all rows in column

    Thanks MrChulo, my data contains confidential information and can range in length from 1 - 50 characters. The key is that for every dataset, it will be the same characters, and they need to be pulled out. The data is realistic, because every time, the data will be formatted similarly. If I had put two sets of names in the data, you would say it isn't realistic because I am only trying to pull out the starting characters from one list at a time.

    Your code does exactly what I was looking for. Thank you very much, appreciate the assistance.

+ 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. Replies: 1
    Last Post: 09-11-2014, 10:59 AM
  2. Find most common (x5) numbers within numerical string range
    By JEWB in forum Excel Formulas & Functions
    Replies: 13
    Last Post: 04-03-2014, 06:59 AM
  3. [SOLVED] Find Most Common Occurring String Based on Lookup Value
    By kolor in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 12-11-2013, 09:17 PM
  4. [SOLVED] Find out the length of common string between cells of two columns.
    By rampulaparthi in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 08-28-2013, 03:25 AM
  5. How to find common string column from two columns??
    By sanil.henry1982 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-14-2012, 08:34 AM
  6. [SOLVED] URGENT find common string values in 2 colums
    By M.Karim in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-13-2012, 11:21 AM
  7. Find the lest common string-value in a range
    By ElmerS in forum Excel General
    Replies: 4
    Last Post: 02-01-2009, 06:25 PM

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