+ Reply to Thread
Results 1 to 21 of 21

Searching for duplicate txt in a Row

  1. #1
    Registered User
    Join Date
    06-12-2016
    Location
    Wareham, UK
    MS-Off Ver
    365 Excel for Mac version 16.81
    Posts
    16

    Searching for duplicate txt in a Row

    Hello
    This is my first post so please be gentle!

    I am using Microsoft Excel for Mac (Version 16.81 from Microsoft 365)

    I am analysing a number of questionnaires which contain information in Row1 that I need to extricate. Here are the steps:

    1. Row 1 has some data followed by (from Column H) text field counting Roles and Organisations (R&O) which are comma separated.
    (e.g. Clinical nurse, CAHS)

    2. The R&O information starts from Column H and probably has a limit of 30 entries.
    3. Each R&O entry is repeated a number of times, dependent upon the questionnaire.
    4. In the example provided (see attached spreadsheet) there are six unique R&Os. I have highlighted the first one ("Senior Community Engagement Officer, Department of Communities") and indicated when it repeated.


    Task:
    Task 1: Find the number of unique R&Os (in this case six)
    Task 2: Store data onto a second sheet (named R&O in the attached sheet). This sheet has been manually developed for illustration of how it should look.
    Task 3: Data to be in two columns headed Role and Organisation



    I have provided my attempt at VBA which does not appear to be working. Again, this is my first VBA attempt.

    Any help/advice would be most welcome.


    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by NellyGrice; 03-28-2024 at 03:17 AM. Reason: Forgot to say it's Excel for Mac

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,848

    Re: Searching for duplicate txt in a Row

    Administrative Note:

    Welcome to the forum.

    Is your forum profile showing the Excel PRODUCT that you need this to work for?

    Members will tailor the solutions they offer to the Office PRODUCT (Excel, NOT Windows) that you have. Please check that your forum profile is up-to-date in this respect. If you aren't sure, in Excel go to File | Account and report what it says below the MS logo at the top of that page. If your product is for Mac, please also state this.

    The three most recent Excel products are Excel 2019, Excel 2021 and MS365 - if you are using MS365, please give this name along with the version number in your profile (e.g. MS365 Version 2306). This is in the About Excel section further down the Account page.

    Thanks.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  3. #3
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,848

    Re: Searching for duplicate txt in a Row

    Please manually mock up in the workbook what you want the VBA (or formula) to produce where you want to see it.

  4. #4
    Registered User
    Join Date
    06-12-2016
    Location
    Wareham, UK
    MS-Off Ver
    365 Excel for Mac version 16.81
    Posts
    16

    Re: Searching for duplicate txt in a Row

    Thank you for your feedback.
    I have mocked the solution in the attached workbook.
    It can be found on the worksheet "R&O"

  5. #5
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,848

    Re: Searching for duplicate txt in a Row

    Please follow my instructions in post #2 - this is important.

    Where has trhe ORGANISATION information come from?

  6. #6
    Registered User
    Join Date
    06-12-2016
    Location
    Wareham, UK
    MS-Off Ver
    365 Excel for Mac version 16.81
    Posts
    16

    Re: Searching for duplicate txt in a Row

    In the first worksheet ("Data") Row 1 , from Column H onwards contains text fields. These are Roles and Organisations (R&O) separated by a comma (CSV).
    For example H1. shows, "Senior Community Engagement Officer, Department of Communities" the first part is the Role ("Senior Community Engagement Officer,") and the second part is the Organisation ("Department of Communities").

  7. #7
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,848

    Re: Searching for duplicate txt in a Row

    Why have you still not answerd my first question in post #2? 8 is NOT a version of Excel - which version are you using?

    If you have 365, you can use this formula:

    =SORT(LET(u,UNIQUE(TRANSPOSE(Data!H1:AE1)),HSTACK(BYROW(u,LAMBDA(r,TEXTBEFORE(r,","))),BYROW(u,LAMBDA(r,TRIM(TEXTAFTER(r,",")))))))
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    06-12-2016
    Location
    Wareham, UK
    MS-Off Ver
    365 Excel for Mac version 16.81
    Posts
    16

    Re: Searching for duplicate txt in a Row

    Thank you for your prompt assitance.
    I stated I was using Microsoft 365 in my earlier response.

  9. #9
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,848

    Re: Searching for duplicate txt in a Row

    But you haven't updated your profile!

    Please do so NOW. Then let me know if the solution offered is suitable, and if not, why not.

    EDIT: Thanks for updating your profile.

  10. #10
    Registered User
    Join Date
    06-12-2016
    Location
    Wareham, UK
    MS-Off Ver
    365 Excel for Mac version 16.81
    Posts
    16

    Re: Searching for duplicate txt in a Row

    profile updated.

  11. #11
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,848

    Re: Searching for duplicate txt in a Row

    Thanks. Let me know if the solution offered is suitable, and if not, why not.

  12. #12
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,848

    Re: Searching for duplicate txt in a Row

    To add the column headers:

    =VSTACK({"Role","Organisation"},SORT(LET(u,UNIQUE(TRANSPOSE(Data!H1:AE1)),HSTACK(BYROW(u,LAMBDA(r,TEXTBEFORE(r,","))),BYROW(u,LAMBDA(r,TRIM(TEXTAFTER(r,","))))))))
    Attached Files Attached Files

  13. #13
    Registered User
    Join Date
    06-12-2016
    Location
    Wareham, UK
    MS-Off Ver
    365 Excel for Mac version 16.81
    Posts
    16

    Re: Searching for duplicate txt in a Row

    Dear AliGW
    It works an absolute treat.
    THANK YOU not only for the solution but also for your patience.

  14. #14
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,848

    Re: Searching for duplicate txt in a Row

    See the improved version just above.

    Glad to have helped.

    If that takes care of your original question, please choose Thread Tools from the menu link above and mark this thread as SOLVED. You can also access the SOLVED tag by editing the opening post and choosing SOLVED from the drop-down to the left of the title box.

    Also, if you have not already done so, remember that you can reward anyone who offered you help towards a solution for your issue by clicking the small star icon (* Add Reputation) located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of each of those who offered help.

  15. #15
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,623

    Re: Searching for duplicate txt in a Row

    By the way, as you asked for macro solution, it could go like the one below:

    I assumed that the number of columns could be different, so run the macro after selecting all cells with dat (in sample file H1:AE1)

    Please Login or Register  to view this content.

    Note that for both Ali's formula and my macro code these are identified as two different entries:
    Deputy Principal, La Grange Remote community school
    Deputy Principal, La Grange Remote School
    Attached Files Attached Files
    Best Regards,

    Kaper

  16. #16
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,466

    Re: Searching for duplicate txt in a Row

    Try this code.
    Please note that some cells have similar content, differing by only (or with excess, or missing) a few characters, which will be treated as separate cases.
    Example:
    "La Grange Remote community school"
    vs
    "La Grange Remote school"

    PHP Code: 
    Option Explicit
    Sub findRO
    ()
    Dim lc&, i&, k&, rngres(1 To 10001 To 2), sp
    Dim dic 
    As Object
    Set dic 
    CreateObject("scripting.dictionary")
    With Sheets("Data")
        
    lc = .Cells(1Columns.Count).End(xlToLeft).Column 'Last used column
        rng = .Range(.Cells(1, "H"), .Cells(1, lc)).Value '
    value of range from H1 to last cell in row 1
    End With
    For 1 To UBound(rng2' loop thru rng
        If InStr(1, rng(1, i), "?") = 0 And rng(1, i) <> "" Then '
    cells contain "?" will be excludednot counted.
            If 
    Not dic.exists(UCase(rng(1i))) Then
                sp 
    Split(rng(1i), ",")
                
    dic.Add UCase(rng(1i)), ""
                
    1res(k1) = sp(0): res(k2) = sp(1)
            
    End If
        
    End If
    Next
    Sheets
    ("R&O").Activate
    Range
    ("A2:B10000").ClearContents
    If 0 Then Range("A2").Resize(k2).Value res
    End Sub 
    Quang PT

  17. #17
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Searching for duplicate txt in a Row

    vba, use of collection as Mac doesn't support CreateObject function.
    Please Login or Register  to view this content.
    Last edited by jindon; 03-28-2024 at 05:40 AM.

  18. #18
    Registered User
    Join Date
    06-12-2016
    Location
    Wareham, UK
    MS-Off Ver
    365 Excel for Mac version 16.81
    Posts
    16

    Re: Searching for duplicate txt in a Row

    Kaper

    SOLVED

    THANKS A MILLION

  19. #19
    Registered User
    Join Date
    06-12-2016
    Location
    Wareham, UK
    MS-Off Ver
    365 Excel for Mac version 16.81
    Posts
    16

    Re: Searching for duplicate txt in a Row

    Jindon

    That's brilliant
    THANK YOU.
    Neil

  20. #20
    Registered User
    Join Date
    06-12-2016
    Location
    Wareham, UK
    MS-Off Ver
    365 Excel for Mac version 16.81
    Posts
    16

    Re: Searching for duplicate txt in a Row

    Bebo

    THANK YOU SO MUCH. I appreciate your response.
    Neil

  21. #21
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,848

    Re: Searching for duplicate txt in a Row

    If you have not already done so, remember that you can reward anyone who offered you help towards a solution for your issue by clicking the small star icon (* Add Reputation) located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of each of those who offered help.

+ 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. Need help searching duplicate values in a column
    By kraut2k in forum Excel General
    Replies: 3
    Last Post: 01-27-2015, 05:29 PM
  2. Searching duplicate fields in a column
    By kraut2k in forum Hello..Introduce yourself
    Replies: 1
    Last Post: 01-27-2015, 04:46 PM
  3. Searching ALMOST duplicate data
    By copythat in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-10-2011, 05:31 AM
  4. Searching for and summing duplicate entries
    By JONNY981 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-15-2010, 07:53 AM
  5. searching for duplicate cells
    By Holly in forum Excel General
    Replies: 1
    Last Post: 07-06-2007, 11:05 AM
  6. Searching for duplicate numbers
    By Uncle Guinness in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 08-10-2006, 06:05 PM
  7. Replies: 1
    Last Post: 10-03-2005, 05:05 AM

Tags for this Thread

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