+ Reply to Thread
Results 1 to 11 of 11

Find And Highlight

  1. #1
    Registered User
    Join Date
    06-29-2011
    Location
    Singapore
    MS-Off Ver
    Excel 2002
    Posts
    5

    Find And Highlight

    Hi guys,

    I've been cracking my brains on this for days, but I haven't got a solution.

    I need to find the texts in cells and highlight them if they duplicate.

    Say I have cells A1 to A4 with the texts: AJC1, AJC2, ACJC-1, AJC3 respectively. I need Excel to highlight cells A1, A2 and A3 because "AJC" appeared 3 times in the A1:A4 array.

    Any solutions? Thanks!
    Last edited by congratx; 07-08-2011 at 11:13 AM.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,014

    Re: Find And Highlight

    =SUMPRODUCT(--(LEFT(A1:A4,3)="AJC")) gives a count of 3.

    You could perhaps use this with Conditional Formatting to highlight the cells.

    Regards
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    06-29-2011
    Location
    Singapore
    MS-Off Ver
    Excel 2002
    Posts
    5

    Re: Find And Highlight

    Quote Originally Posted by TMShucks View Post
    =SUMPRODUCT(--(LEFT(A1:A4,3)="AJC")) gives a count of 3.

    You could perhaps use this with Conditional Formatting to highlight the cells.

    Regards
    Hi,

    Thanks for your help. But I realised, when the name has hyphens, like "ACJC-1," that formula doesn't work anymore. Add wildcards like * doesn't help too.

    Any way to work around it?

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,014

    Re: Find And Highlight

    I'm struggling with what you're trying to achieve. Please post a sample workbook with some typical data.

    Regards

  5. #5
    Registered User
    Join Date
    06-29-2011
    Location
    Singapore
    MS-Off Ver
    Excel 2002
    Posts
    5

    Re: Find And Highlight

    Sorry, I can't upload an attachment. No idea why.

    So I copied it out. Hope you can understand.

    A
    1 AJC1
    2 AJC2
    3 ACJC-1
    4 AJC3
    5 MJC-3
    6 PJC-1
    7 MJC-7
    8 RI-E
    9 YJC-1
    10 RI-D
    11 MJC-8

    So I need the cells to be highlighted, when there are 3 or more occurences of the names. In this case, both "AJC" and "MJC" appeared thrice. Thus, cells A1, A2, A4, A5, A7 and A11 need to be highlighted.

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,014

    Re: Find And Highlight

    See attached example workbook.


    Regards
    Attached Files Attached Files

  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,014

    Re: Find And Highlight

    This caters for blank cells in the range:

    =AND($A1<>"",SUMPRODUCT(--(LEFT($A$1:$A$18,3)=LEFT($A1,3)))>=3)


    Regards

  8. #8
    Registered User
    Join Date
    06-29-2011
    Location
    Singapore
    MS-Off Ver
    Excel 2002
    Posts
    5

    Re: Find And Highlight

    Quote Originally Posted by TMShucks View Post
    This caters for blank cells in the range:

    =AND($A1<>"",SUMPRODUCT(--(LEFT($A$1:$A$18,3)=LEFT($A1,3)))>=3)


    Regards
    So sorry for my late reply.

    I've tested the formulas. They seem to work well. Thanks!

    But can I ask what the formulas mean?

    What's the use of "SUMPRODUCT(--" and I can't understand why MJC is highlighted, when you equate to LEFT($A1,3). It is what I wanted, but doesn't that mean you are just looking for AJC?

  9. #9
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,014

    Re: Find And Highlight

    SUMPRODUCT is creating an array of the elements in the range A1 to A18 and then comparing them to the value in A1, effectively producing a count of the cells satisfying the condition. The -- is coercing the result into a numeric value.

    Notice that the array is being compared to $A1 which means the row number will adjust for each row comparison, whereas the range is absolute and doesn't change. Actually, the $A is not essential in this case but it would allow you to apply the CF to other cells on the row.

    So what you're getting is individual comparisons

    =AND($A1<>"",SUMPRODUCT(--(LEFT($A$1:$A$18,3)=LEFT($A1,3)))>=3)
    =AND($A2<>"",SUMPRODUCT(--(LEFT($A$1:$A$18,3)=LEFT($A2,3)))>=3)
    :
    =AND($A18<>"",SUMPRODUCT(--(LEFT($A$1:$A$18,3)=LEFT($A18,3)))>=3)


    Regards

  10. #10
    Registered User
    Join Date
    06-29-2011
    Location
    Singapore
    MS-Off Ver
    Excel 2002
    Posts
    5

    Re: Find And Highlight

    I see.

    It works like a charm! Thanks so much for your help

  11. #11
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,014

    Re: Find And Highlight

    You're welcome.

    If this answers your question, please mark your thread as solved. See my signature for details or the FAQ.

    Regards

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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