+ Reply to Thread
Results 1 to 11 of 11

Change background color of duplicate, clear duplicates & leave background color changed

  1. #1
    Forum Contributor
    Join Date
    03-27-2022
    Location
    MS, USA
    MS-Off Ver
    Microsoft 365
    Posts
    143

    Change background color of duplicate, clear duplicates & leave background color changed

    Hi,

    I am seeking a VBA that will change the background color orange of the duplicates and clear the duplicates, but I seek for the background color to remain changed to orange. The purpose is to track that a defect had multiple issues on one piece with the orange color, but not double, triple count the issues that occurred on one part as multiple different occurrences for a different report. I thought about conditional formatting, but wasn't sure how to keep the background the same color, after the duplicate is removed.

    1. Find duplicate rows with matching information of Date, Shift, Broadcast, and Duon Location.
    2. If there is a duplicate with that information, I seek to change the Duon Location cell background color "Orange" of the duplicates.
    3. Clear the value of the duplicate from A:L.
    4. Leave the remaining row of data with an Orange background in the Duon Location cell.

    Thank you for any help or guidance in this process.
    Attached Files Attached Files
    Last edited by Ajaxs87; 01-06-2023 at 12:04 AM.

  2. #2
    Forum Expert Crooza's Avatar
    Join Date
    10-19-2013
    Location
    Hunter Valley, Australia
    MS-Off Ver
    Excel 2003 /7/10
    Posts
    2,082

    Re: Change background color of duplicate, clear duplicates & leave background color chang

    Try this

    Please Login or Register  to view this content.
    Happy with my advice? Click on the * reputation button below

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

    Re: Change background color of duplicate, clear duplicates & leave background color chang

    Try:
    PHP Code: 
    Option Explicit
    Sub clearDup
    ()
    Dim lr&, i&, j&, rngid As String
    Dim dic 
    As Objectitems
    Set dic 
    CreateObject("Scripting.dictionary")
    lr Cells(Rows.Count"A").End(xlUp).Row
    rng 
    Range("A2:I" lr).Value
    For 1 To UBound(rng)
        
    id rng(i1) & "|" rng(i2) & "|" rng(i3) & "|" rng(i9'id = combine 4 key columns
        If Not dic.exists(id) Then
            dic.Add id, i + 1
        Else
            dic(id) = dic(id) & "-" & i + 1 ' 
    store the row#
        
    End If
    Next
    For Each item In dic.items
        
    If InStr(1item"-"Then
            s 
    Split(item"-")
            For 
    0 To UBound(s)
                
    With Cells(s(i), "A")
                    .
    Resize(112).ClearContents
                    
    .Offset(, 8).Interior.ColorIndex 40 ' orange color index = 40
                End With
            Next
        End If
    Next
    End Sub 
    Quang PT

  4. #4
    Forum Contributor
    Join Date
    03-27-2022
    Location
    MS, USA
    MS-Off Ver
    Microsoft 365
    Posts
    143

    Re: Change background color of duplicate, clear duplicates & leave background color chang

    Quote Originally Posted by Crooza View Post
    Try this

    Please Login or Register  to view this content.
    Thank you! This is very close to the outcome I am seeking,

    I was seeking for the duplicate that wasn't cleared out to have the orange in the background, but just in the cell in column [Duon Location]. You are awesome! I attached an image for reference of the outcome I am seeking.


    @bebo021999 I couldn't get the vba to work. It wasn't showing up in my macros list when I copied and pasted it into a module. Thank you for your time and energy in this code
    Attached Images Attached Images

  5. #5
    Forum Expert Crooza's Avatar
    Join Date
    10-19-2013
    Location
    Hunter Valley, Australia
    MS-Off Ver
    Excel 2003 /7/10
    Posts
    2,082

    Re: Change background color of duplicate, clear duplicates & leave background color chang

    just change this row then

    from

    Range("A" & nextrow & ":L" & nextrow).Interior.ThemeColor = xlThemeColorAccent2

    to

    Range("I" & nextrow).Interior.ThemeColor = xlThemeColorAccent2

  6. #6
    Forum Contributor
    Join Date
    03-27-2022
    Location
    MS, USA
    MS-Off Ver
    Microsoft 365
    Posts
    143

    Re: Change background color of duplicate, clear duplicates & leave background color chang

    Quote Originally Posted by Crooza View Post
    just change this row then

    from

    Range("A" & nextrow & ":L" & nextrow).Interior.ThemeColor = xlThemeColorAccent2

    to

    Range("I" & nextrow).Interior.ThemeColor = xlThemeColorAccent2
    Thank you for your continued support, this is the outcome I was getting when I altered the code as suggested, it is still highlighting the cell in the row with the data cleared out. I seek for it to show orange of the duplicate that remains with data in the row.
    Attached Images Attached Images

  7. #7
    Forum Expert Crooza's Avatar
    Join Date
    10-19-2013
    Location
    Hunter Valley, Australia
    MS-Off Ver
    Excel 2003 /7/10
    Posts
    2,082

    Re: Change background color of duplicate, clear duplicates & leave background color chang

    OK. In your original post you said you wanted the cells cleared from Columns A to L. This is column I so falls in the middle. Do you want columns A to H cleared and then J to L cleared? If so use this macro.
    Please Login or Register  to view this content.

  8. #8
    Forum Contributor
    Join Date
    03-27-2022
    Location
    MS, USA
    MS-Off Ver
    Microsoft 365
    Posts
    143

    Re: Change background color of duplicate, clear duplicates & leave background color chang

    My apologizes for my lack of wording.

    So in the original post, row 4 and row 8, have the same data in columns A,B,C & I.

    - I seek for row 8 to be cleared from A:L, as it is a duplicate and effects how we score the total.

    - I seek for row 4, to have the background color changed to orange in column I, to inform the reader that there was a duplicate with that information. As the root cause for the duplicate is a specific thing that , we want to take notes of.

    - Currently, it clears row 8 and highlights column I in row 8 as well. Which doesn't allow me to link the duplicate to any data, as it has been cleared out.

    I apologize once again, if I am not wording my request correctly.

  9. #9
    Forum Expert Crooza's Avatar
    Join Date
    10-19-2013
    Location
    Hunter Valley, Australia
    MS-Off Ver
    Excel 2003 /7/10
    Posts
    2,082

    Re: Change background color of duplicate, clear duplicates & leave background color chang

    Got it. Thanks.

    Change this

    Please Login or Register  to view this content.
    to this
    Please Login or Register  to view this content.
    and let me know if that does the trick

  10. #10
    Forum Contributor
    Join Date
    03-27-2022
    Location
    MS, USA
    MS-Off Ver
    Microsoft 365
    Posts
    143

    Re: Change background color of duplicate, clear duplicates & leave background color chang

    Quote Originally Posted by Crooza View Post
    Got it. Thanks.

    Change this

    Please Login or Register  to view this content.
    to this
    Please Login or Register  to view this content.
    and let me know if that does the trick
    Thank you Crooza! I am grateful for your time, knowledge and patience

  11. #11
    Forum Expert Crooza's Avatar
    Join Date
    10-19-2013
    Location
    Hunter Valley, Australia
    MS-Off Ver
    Excel 2003 /7/10
    Posts
    2,082

    Re: Change background color of duplicate, clear duplicates & leave background color chang

    No problems. We got there in the end. Thanks for the Rep too.

+ 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. change background textbox color based on text color in cell
    By atadaliran in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-05-2021, 05:34 AM
  2. Replies: 8
    Last Post: 04-02-2016, 04:00 AM
  3. Change cell background color based on another cells background color
    By Queo in forum For Other Platforms(Mac, Google Docs, Mobile OS etc)
    Replies: 4
    Last Post: 06-10-2014, 05:28 AM
  4. Change background color of cell when data has been changed
    By paperboy in forum Excel - New Users/Basics
    Replies: 12
    Last Post: 09-13-2013, 05:00 AM
  5. [SOLVED] Macro to change all cells with a certain background color in another background color
    By kevinvzandvoort in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-13-2012, 11:04 AM
  6. change text color based on background color
    By great.bean in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-05-2009, 07:07 PM
  7. how can I conditionally change font color, or background color?
    By MOHA in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-21-2006, 01:57 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