0

I have a huge sales data sheet from range D3 to BC1415 but here is my problem:

I have made several scorecards from this data sheet but duplicates are ruining everything. I have organised my scorecards in a way where Excel cannot see the difference between 15 apples that were sold during week A and 15 apples sold during week B(in my Top 15 week sales, the week A pops up two times and week B doesn't at all).

I'm halfway through the solution but I just don't have enough expertise in VBA yet to complete it:

I would like to add +0.001 to all duplicates except the first until there is no duplicate left in order to allow Excel to differentiate them. Would that be possible?

This doesn't seem to work but I believe it is the way to go:

  • Conditional formatting=COUNTIF($A$1:A1,A1)>1 so only second and more duplicate occurrences get formatted.

  • Then select all formatted cells with


Sub selectCFColours()
    Dim cell As Range
    Dim selRange As Range

    For Each cell In Range("A1:V1")
        If cell.DisplayFormat.Interior.Color <> cell.Interior.Color Then
            If selRange Is Nothing Then
                Set selRange = cell
            Else
                Set selRange = Union(selRange, cell)
            End If
        End If
    Next

    If Not selRange Is Nothing Then selRange.Select
End Sub

-Special pasting 0.001 with "Add" setting on all selected cells.

For some reasons this doesn't work.

1 Answer 1

2

I'm going to answer this question: "understand why my method doesn't work"

Your VBA is not working because it is selecting cells based on their interior.color value, but the colors set by conditional formatting don't populate the interior.color property.

That value is set to whatever the manual formatting is, and for your screen the conditional formatting is displayed on top.

8
  • 1
    To expand on Greg's answer, you need to use the DisplayFormat property Commented May 8, 2019 at 15:48
  • Thank you for your answers!! I am new to VBA and I am not quite sure how I could adapt my code using the DisplayFormat property? My Conditional Formatting fills the cell with 255 (red) and it seems that my 'selectCFcolours' function actually selects the cells that are colored with my Conditional Formating! The issue is when I have to repeat the operation until there is no duplicates: I would like to create a loop, that would be a big time save Commented May 8, 2019 at 16:00
  • @ArthurPenot if you're doing this to remove duplicates, why not use Range.RemoveDuplicates? Commented May 8, 2019 at 16:19
  • @MathieuGuindon Because I want to keep these duplicates but find a way to make each one of them unique.. 15 apples sold from week A would be different from 15.001 apples sold in week B which would also be different from 15.002 sold in week C. Commented May 8, 2019 at 16:21
  • @ArthurPenot "15 apples sold week A, 15 apples sold week B" -> have a column for the week number or the transaction date, and make your report take the week/date into account. SUMIFS comes to mind. Add metadata, don't alter the sales figures. You didn't sell 15.0001 apples week A. Commented May 8, 2019 at 16:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .