+ Reply to Thread
Results 1 to 3 of 3

Macro to Count Duplicate Values

Hybrid View

Jiptastic Macro to Count Duplicate... 04-13-2013, 12:24 PM
mehmetcik Re: Macro to Count Duplicate... 04-13-2013, 05:45 PM
stnkynts Re: Macro to Count Duplicate... 04-13-2013, 10:13 PM
  1. #1
    Forum Contributor
    Join Date
    09-25-2012
    Location
    Ventura, united States
    MS-Off Ver
    Excel 2010
    Posts
    346

    Macro to Count Duplicate Values

    I am using the conditional formatting to highlight duplicate values. Then I want to check for all the highlighted cells and count the duplicates (dividing by 2). The conditional formatting records the interior color used to highlight is 13551615, but it doesn't recognize that the highlighted cells are this color later.

    To highlight duplicates

    Selection.FormatConditions.AddUniqueValues
        Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
        Selection.FormatConditions(1).DupeUnique = xlDuplicate
        With Selection.FormatConditions(1).Font
            .Color = -16383844
            .TintAndShade = 0
        End With
        With Selection.FormatConditions(1).Interior
            .PatternColorIndex = xlAutomatic
            .Color = 13551615
            .TintAndShade = 0
        End With
    To count highlighted cells

    Sub Dup_Check2()
    
    Dim RowsEnd As Integer
    RowsEnd = Range("A" & Rows.Count).End(xlUp).Row
    
    For i = 1 To RowsEnd
    If Cells(i, 1).Interior.Color = 13551615 Then
    Duplicate_Count = Duplicate_Count + 1
    End If
    
    Next
    
    End Sub

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Macro to Count Duplicate Values

    I have checked with a bit of code and:

    It looks like Excel doesn't recognise the fact that the color is changed by a conditional format.

    You may have to check for duplicates in Visual Basic

    .Interior.Color returns the "real" color, not the conditionally-formatted color result..
    Last edited by mehmetcik; 04-13-2013 at 05:52 PM.

  3. #3
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Macro to Count Duplicate Values

    Pearson spells it out really nicely here: http://www.cpearson.com/excel/CFColors.htm

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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