• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 341
  • Last Modified:

Trouble with Excel Array Formulas + Conditional Formatting

I want to compare a range of cells with other ranges of cells and do a conditional format based on the result.  Here is an example of what I'm asking:

Name1   A   B   C   D
Name2   B   A   C   D
Name3   A   B   D   C
Name4   A   B   C   D

I want to make the background of the Name1 cell blue, becasue the text values in the following cells {A,B,C,D} match those for Name4.  Likewise Name4 cell background should turn blue, because its following values match those of Name1.  If a Name had a unique sequence of text values following it (e.g. Name2 and Name3), the cell background would remain at the default colour.

I have 54 names in total and have tried a lot of different formulas, but I'm not an Excel expert and maybe this is a simple problem for someone out there.  Any help would be greatly appreciated.  Thanks!!
0
cawleym
Asked:
cawleym
1 Solution
 
criCommented:
My gut feeling: Using array formulas + conditional formatting is too complicated in your case (should it work at all). A work-around could be much simpler. Therefore:

a) Is the purpose to identify duplicates regarding columns 2,3,4,5 ?
b) Is using an auxiliary column acceptable ?
c) Will the number of rows increase in the future ?
 

0
 
MoliereCommented:
I think this requires a macro like the following. I assume that you have the data in A1:E5 with a header in the first row. Correct me if I am wrong.

Sub HighlightDupes()
Dim AreaRange As Range, ARRows As Integer
    Set AreaRange = Range(Cells(1, 1), Cells(1, 1).End(xlDown).Offset(0, 4))
    ARRows = AreaRange.Rows.Count
    AreaRange.Sort Key1:=Range("E1"), Key2:=Range("D1"), Header:=xlYes
    AreaRange.Sort Key1:=Range("C1"), Key2:=Range("B1"), Header:=xlYes
   
    Range(Cells(2, 6), Cells(1, 6).Offset(ARRows - 1, 0)).FormulaR1C1 = "=OR(AND(RC2=R[-1]C2,RC3=R[-1]C3,RC4=R[-1]C4,RC5=R[-1]C5),AND(RC2=R[1]C2,RC3=R[1]C3,RC4=R[1]C4,RC5=R[1]C5))"
    For i = 2 To ARRows
        If Cells(i, 6) Then
            With Cells(i, 1).Interior
                .ColorIndex = 34
                .Pattern = xlSolid
            End With
        End If
    Next i
   
    Columns(6).Delete
    AreaRange.Sort Key1:=Range("A1"), Header:=xlYes
End Sub
0
 
cawleymAuthor Commented:
Cri and Moliere ... thanks for your comments.

Cri:
a) the purpose is to identify rows which have duplicate data in columns 2-8 (B-H), though my example didn't show that much.
b) an auxiliary column is definitely acceptable.
c) no. the number of rows is fixed.

Moliere:
The data is in B6:H59.  Will the macro be able to handle that much data?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
iaminitCommented:
This may not be the slickest answer, but ...
you could add a column (e.g., column I) that concatenates columns B through H -- i.e., =B6&C6&D6&E6&F6&G6&H6.  And copy that to all the rows.  Then add the conditional format to cell A6 --
=COUNTIF($I$6:$I$59,I6)>1
Even better would be to name the range I6:I59 and use the range name in the conditional format just in case you need to expand your range down the road.
0
 
criCommented:
cawleym, iaminit's solution is one of the two I would have suggested. If you want to get rid of the duplicates I would have suggested to sort the range, first using the concatenated column to group the duplicates, delete them manually, and then resort in the required order (perhaps using a previously added ranking column)
0
 
cawleymAuthor Commented:
Hi Iaminit ... thanks for the solution!  I know it's not the slickest answer but it does the job.

Thanks also cri and moliere for your earlier suggestions.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now