+ Reply to Thread
Results 1 to 4 of 4

Need to remove non-matching text from a delimited string

  1. #1
    Registered User
    Join Date
    05-02-2019
    Location
    CA
    MS-Off Ver
    Office 365
    Posts
    2

    Need to remove non-matching text from a delimited string

    I have an Excel database query to get all the RBAC user roles that are assigned to each user, and the database returns a string delimited by & (ampersands) between each user role, e.g.:
    Please Login or Register  to view this content.
    My query filters records that only have a matching string, let's say it's "Reports". However it still returns the full list of user roles for a matching user, and in this case some users have >10 roles assigned and it makes the table look really messy and not suitable for printing.

    I could manually clean up each row, but there are quite a lot of them, and since this is going to be run regularly I'm wondering if there may be a good Excel formula or VBS method to split delimited sections of a string and only keep ones that match a string criteria.

    I'm aware of "Text to Columns" and its ability to make use of delimiters, but it just spat out a ton of columns and made things worse. I've done several searches about cleaning up delimited strings in Excel but couldn't find any results that were similar to my situation: need to split a delimited string and do something RegEx-esque to only keep parts that match a pattern.

    Ideally I'd like to keep the cleaned up results in a single cell, so the above example "&Admin&Supervisor&ViewReports&WriteReports&" would look like:
    Please Login or Register  to view this content.
    or
    Please Login or Register  to view this content.
    or similar, in a single cell. Not too picky about formatting really, just need the non-relevant parts of the string gone.


    I was given this formula on another website:
    Please Login or Register  to view this content.
    With {3,5} it gives me the 2nd and 4th substring, so "Supervisor WriteReports". However I can't figure out how to make it work off of a MATCH instead of numerical indexes, and the numerical indexes just aren't helpful since an account could have 3 user roles or over 15. I'd need to match it to "*Reports*" but I can't figure out the syntax of this formula or what goes where to work in the MATCH function.

    Any help or ideas would be appreciated, thanks.
    Last edited by bramsey; 05-02-2019 at 05:26 PM. Reason: Solved!

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Need to remove non-matching text from a delimited string

    Hi, and welcome to the forum.

    Does this UDF help.
    With the record in A1 and the comparison text e.g. 'Reports' in B1

    use
    Formula: copy to clipboard
    Please Login or Register  to view this content.



    Please Login or Register  to view this content.
    Last edited by Richard Buttrey; 05-02-2019 at 01:40 PM.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Registered User
    Join Date
    05-02-2019
    Location
    CA
    MS-Off Ver
    Office 365
    Posts
    2

    Re: Need to remove non-matching text from a delimited string

    Wow, thank you so much! That worked like a charm!

    For readability I'm just going to need need to remove the first "&" character from the string but I should be able to figure that out pretty easily. Thanks again!

    EDIT: For the record, I just removed cruft from the string after the fact by doing this at the end:
    Please Login or Register  to view this content.
    Last edited by bramsey; 05-02-2019 at 05:41 PM.

  4. #4
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Need to remove non-matching text from a delimited string

    My pleasure and thanks for the rep.

+ 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. Formula to take a column to row, delimited by certain text string
    By LightingPop in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 01-23-2015, 03:49 PM
  2. [SOLVED] Semi-colon Delimited String Contains Text Occuring in Column
    By The831st in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-04-2014, 06:28 AM
  3. [SOLVED] Search text in cells, find matching text based on list, remove all but one entry
    By adam_mc in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 01-30-2013, 12:50 PM
  4. [SOLVED] UDF to remove "equivalent" expressions from a ";" delimited string
    By dredwolf in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-08-2012, 07:25 PM
  5. Replies: 21
    Last Post: 08-13-2012, 01:52 PM
  6. Importing Delimited Text/Exporting Delimited Text Loop
    By cecarter74 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-05-2009, 01:17 PM
  7. Replies: 5
    Last Post: 02-10-2006, 06:35 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