Results 1 to 6 of 6

Highlight Alternate Duplicate Cells Based on Selection

Threaded View

  1. #1
    Registered User
    Join Date
    01-04-2018
    Location
    Bristol
    MS-Off Ver
    2016
    Posts
    5

    Highlight Alternate Duplicate Cells Based on Selection

    Hi All,

    Thanks for your help in advance.

    I have a piece of code which will highlight all duplicates in a row with alternate colours:

    Sub colouralternaterows()
    Dim Rng As Range, Dn As Range, K As Variant, c As Long
    Set Rng = Range(Range("F2"), Range("F" & Rows.Count).End(xlUp))
    With CreateObject("scripting.dictionary")
    .CompareMode = vbTextCompare
    For Each Dn In Rng
        If Not .Exists(Dn.Value) Then
            .Add Dn.Value, Dn
        Else
            Set .Item(Dn.Value) = Union(.Item(Dn.Value), Dn)
        End If
    Next
    For Each K In .keys
        c = c + 1
        If c Mod 2 = 0 Then
            .Item(K).Interior.Color = RGB(255, 242, 204)
            Else
             .Item(K).Interior.Color = RGB(217, 217, 217)
        End If
    Next K
    End With
    
    End Sub
    I was wondering if anyone knew a way I could set the macro to look within a selection, i.e. I select row A, or A2:A200 manually, and I can then run the code through selecting the module through the quick access toolbar. (Without having to set the range within the code each time.)

    The data will be in text form, i.e:

    Ben Smith
    Ben Smith
    John Doe
    John Doe
    Alice Evans
    Alice Evans
    Ana Smith
    Ana Smith
    James Smith
    James Smith
    James Smith
    Daria Burton
    Daria Burton

    Thanks again for your help,

    Alex
    Last edited by dxz; 04-10-2018 at 10:27 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Highlight cells based on dropdown selection
    By fbhav in forum Excel - New Users/Basics
    Replies: 11
    Last Post: 01-04-2021, 03:17 AM
  2. [SOLVED] Highlight cells based on drop down selection
    By cbetsinger in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-02-2017, 09:23 PM
  3. [SOLVED] Highlight particular rows based on cell selection
    By chickpeazy in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 05-31-2017, 10:13 AM
  4. Highlight duplicate based on a different columns contents
    By spidervarient in forum Excel General
    Replies: 6
    Last Post: 05-08-2017, 03:49 PM
  5. Replies: 1
    Last Post: 07-03-2013, 10:50 AM
  6. Replies: 0
    Last Post: 07-22-2011, 12:11 PM
  7. VB - Highlight a selection of cells
    By adgjqetuo in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-02-2009, 04:33 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