+ Reply to Thread
Results 1 to 8 of 8

Duplicate values within same row

  1. #1
    Registered User
    Join Date
    01-08-2015
    Location
    Australia
    MS-Off Ver
    Mac 2011
    Posts
    75

    Duplicate values within same row

    Hi,
    I'm trying to highlight duplicate values within the same row. I've been able to use the formula [=COUNTIFS($C2:$G2,C2)>1] with Conditional Formatting to do this (see attached). Although if there are different duplicate values within the same row then I'd like to colour them with different colours. Is this possible?

    Screenshot 2023-07-31 at 7.03.41 am.png
    Attached Images Attached Images

  2. #2
    Valued Forum Contributor
    Join Date
    02-06-2014
    Location
    N/A
    MS-Off Ver
    N/A
    Posts
    373

    Re: Duplicate values within same row

    Would you be able to upload an example workbook for me to use? I think I can code out something for you fairly easily.

  3. #3
    Registered User
    Join Date
    01-08-2015
    Location
    Australia
    MS-Off Ver
    Mac 2011
    Posts
    75

    Re: Duplicate values within same row

    Thank you. I think I've uploaded it correclty.
    Attached Files Attached Files
    Last edited by Littlesimon; 07-31-2023 at 08:21 AM.

  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
    44,445

    Re: Duplicate values within same row

    I think you would need separate CF formulae for each of the possibilities. For example. 0.5, 1.0, 1.5, 2.0, D, F, etc. I suspect that may not be scalable.
    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


  5. #5
    Valued Forum Contributor
    Join Date
    02-06-2014
    Location
    N/A
    MS-Off Ver
    N/A
    Posts
    373

    Re: Duplicate values within same row

    Quote Originally Posted by Littlesimon View Post
    Thank you. I think I've uploaded it correclty.
    Ok, I think I've solved for this request. I've create a sub that will:

    **NOTE: You need to remove conditional formatting from the sheet for the macro to functionally work (otherwise the conditional format will take precedence over what the macro is trying to accomplish.)
    1.) Target a passed in worksheet reference
    2.) Loop through each cell in UsedRange Column A
    3.) Nested double loop through each UsedRange in the row of the iteration in #2 (we're looping through the rows, then nested double-looping through all the used cells in each row)
    4.) Check for equality, and that the cell references are not targeting the same cell
    5.) If both cells are equal and un-highlighted, highlight them based on a priority list in the Color List sheet (configurable by you as you'd like)
    6.) If one of the cells is already highlighted, set the other cell to that highlight.
    7.) I hooked the sub up to a on-change event in the VBA module for the Test Sheet to give you an example, if you type a new value or paste in new data, it should re-run the macro on the sheet. You can do this for any/all sheets, or just trigger the macro through a manual process.

    You can manually fire the macro like this in a VBA module:
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Last edited by 1aaaaaaaaaaaaaaa; 07-31-2023 at 11:21 AM.

  6. #6
    Registered User
    Join Date
    01-08-2015
    Location
    Australia
    MS-Off Ver
    Mac 2011
    Posts
    75

    Re: Duplicate values within same row

    Thank you WilliamSmithE,

    This does the job well in your example and I like that it changes as data is added/changed. As I'm not the best with VBA, I can see where the following code is although where does the code from above sit? I couldn't apply it to the other sheets.

    Please Login or Register  to view this content.
    After looking at your example, it would be great if the same duplicate values across the sheet are the same colour instead of the first set of duplicate values within a row e.g. the duplicate 'F' values in row 4 are the same colour as the duplicate 'F' values in row 13 but different to the duplicate '0.5' values in row 7. I didn't specify this though and it may require too much of a change in your solution.

    I made a mistake when uploading the example spreadsheet as I didn't remove names from the other tabs in the spreadsheet. Would you be able to remove the one you uploaded and re-upload it without those sheets? Sorry.

    Thank you again for your assistance. It is much appreciated.

  7. #7
    Valued Forum Contributor
    Join Date
    02-06-2014
    Location
    N/A
    MS-Off Ver
    N/A
    Posts
    373

    Re: Duplicate values within same row

    I removed the upload.

    For an automatic kick off

    You need to open the VBA code editor and add that code block you shared into each sheet object that you want the code to auto fire in.

    Please Login or Register  to view this content.
    For a manual kick off:

    In the VBA code editor, create a new code module (google how to do this if needed, it's very easy).

    In the code module create a new sub, something like:

    Please Login or Register  to view this content.
    Change the "MySheet" to the name of the sheet.


    For your additional requirements, could I have you please be very clear on what you're asking for? If you can illustrate it with an example workbook even better.
    Last edited by 1aaaaaaaaaaaaaaa; 07-31-2023 at 11:28 AM.

  8. #8
    Registered User
    Join Date
    01-08-2015
    Location
    Australia
    MS-Off Ver
    Mac 2011
    Posts
    75

    Re: Duplicate values within same row

    Thank you WilliamSmithE,

    I was able to get it to work on all of the sheets.

    When looking at the colouring of the duplicate values, it is colouring the first instance of duplicate values in the row red. Then the next orange and then following the colouring sequence set in 'Colour List' tab. It would be easier to interpret if the duplicate values were coloured based on their value e.g. 0.5 duplicate values in row = red, F duplicate values in row = orange, F.5 duplicate values in row = yellow. See attached spreadsheet.
    Attached Files Attached Files

+ 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. [SOLVED] Removing duplicate rows based on single column duplicate values
    By Miasav90 in forum Excel General
    Replies: 7
    Last Post: 09-23-2021, 08:40 AM
  2. Highlight or display duplicate rows not duplicate values
    By olga6542 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 11-20-2019, 03:24 PM
  3. Replies: 1
    Last Post: 10-12-2018, 12:19 PM
  4. Macros to delete entire duplicate row for duplicate values
    By cutelebel in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-19-2014, 12:09 PM
  5. Replies: 1
    Last Post: 03-03-2014, 11:06 AM
  6. VBA helps needed to Sum duplicate values and delete duplicate rows
    By krjoshi in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-03-2013, 11:40 PM
  7. [SOLVED] Sum Duplicate values then delete duplicate rows
    By keekdapolak in forum Excel General
    Replies: 7
    Last Post: 09-20-2012, 02:57 PM

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