+ Reply to Thread
Results 1 to 6 of 6

Duplicate Characters in a cell

  1. #1
    Forum Contributor
    Join Date
    07-31-2012
    Location
    Cape Town South Africa
    MS-Off Ver
    Excel 2007
    Posts
    133

    Duplicate Characters in a cell

    Hi all

    I am not sure whether this can be done with a function/formula or with VBA, hence posting this query in general. A neat formula however would be the best solution, coz the number of entries varies, in the workbook attached I have 14 different cases though. I need to know when a cell does not repeat any of the possible 7 letters, in each given cell. If there is repitition then leave the cell blank , if all four of the letters are different then place "NR" in the cell. Please see attached wrkbk
    for example.

    Thanking you in advance

    Floyd
    Attached Files Attached Files

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Duplicate Characters in a cell

    This works for 4 digits, in B6, then copied down:

    =IF(OR(ISNUMBER(SEARCH(LEFT(D6,1), MID(D6,2,3))), ISNUMBER(SEARCH(MID(D6,2,1), MID(D6,3,2))), MID(D6,3,1)=RIGHT(D6,1)), "", "NR")


    Not sure about varying lengths.
    Last edited by JBeaucaire; 02-18-2013 at 10:42 AM.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Duplicate Characters in a cell

    Here's a formula that will work for any length string. Put this array formula in B6:

    =IF(OR(ISNUMBER(SEARCH(MID(D6, ROW(INDIRECT("1:" & LEN(D6)-1)), 1), MID(D6, ROW(INDIRECT("2:" & LEN(D6))), LEN(D6))))), "", "NR")

    ...and confirm it by pressing CTRL-SHIFT-ENTER to activate the array. You will know an array is active when you see curly braces { } appear around your formula. If you just press ENTER the formula will always result in NR.

    After entering the formula with CTRL-SHIFT-ENTER, copy downward.

  4. #4
    Forum Contributor
    Join Date
    07-31-2012
    Location
    Cape Town South Africa
    MS-Off Ver
    Excel 2007
    Posts
    133

    Re: Duplicate Characters in a cell

    Thanks a mill!! Always amazed at what you guys can do!

  5. #5
    Forum Expert newdoverman's Avatar
    Join Date
    02-07-2013
    Location
    Port Dover, Ontario, Canada
    MS-Off Ver
    2010
    Posts
    10,330

    Re: Duplicate Characters in a cell

    Using JBeaucaire's formula, I added to it to check that the characters in the list actually exist in the allowed characters. If there is a character in the string being checked that isn't allowed, and "illegal character" is returned.

    =IFERROR(IF(AND((SEARCH(LEFT(D6,1),$D$2,1)>0),(SEARCH(MID(D6,2,1),$D$2,1)>0),(SEARCH(MID(D6,2,1),$D$2,1)>0),(SEARCH(MID(D6,3,1),$D$2,1)>0),(SEARCH(MID(D6,4,1),$D$2,1)>0)),IF(OR(ISNUMBER(SEARCH(LEFT(D6,1), MID(D6,2,3))), ISNUMBER(SEARCH(MID(D6,2,1), MID(D6,3,2))), MID(D6,3,1)=RIGHT(D6,1)), "", "NR")),"Illegal Character")

    Hope this helps.

  6. #6
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Duplicate Characters in a cell

    That was a good idea, NewDoverman.

    Here's the same idea added to the better array formula from post #3. This is also an array:

    =IF(OR(NOT(ISNUMBER(SEARCH(MID(D6, ROW(INDIRECT("1:" & LEN(D6))), 1), $D$2)))), "Illegal", IF(OR(ISNUMBER(SEARCH(MID(D6,1, 1), MID(D6,2,3))), ISNUMBER(SEARCH(MID(D6,2,1), MID(D6,3,2))), MID(D6,3,1)=RIGHT(D6,1)), "", "NR"))

+ 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