HIGHLIGHTS SETS OF 4 EQUAL VALUES WITH DIFFERENT COLORS

RIC63

New Member
Joined
Jan 12, 2015
Messages
16
Office Version
  1. 2016
  2. 2010
Platform
  1. Windows
I need to highlight each set of four equal values found in the 4 columns, each set with a different color.
Values that repeat two or three times should not be highlighted.
Eg. 60 is present in all 4 columns so it must be highlighted eg. in red, 67 in yellow and so on

thanks if anyone can help me about it
 

Attachments

  • 4highlights.jpg
    4highlights.jpg
    133.1 KB · Views: 8

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Could a number show up in the same column more than once? If so, how do you want to handle that? How many rows does your data have? Do you have any idea how many sets of 4 you might have? Conditional Formatting probably won't work for you, since each custom formula only allows 1 color. (Some built-in CF rules have multiple colors, but I don't see how to use those here.) If you only expect a limited number of sets, we could set up a limited number of rules (3 or 4?) that might work. Otherwise, you'll need a VBA macro to do this. Would that work for you? Even a macro though would require a list of the color values you want to highlight the cells with, so if you have a lot of sets, we'll probably end up repeating some colors. Let me know.
 
Upvote 0
Could a number show up in the same column more than once? If so, how do you want to handle that? How many rows does your data have? Do you have any idea how many sets of 4 you might have? Conditional Formatting probably won't work for you, since each custom formula only allows 1 color. (Some built-in CF rules have multiple colors, but I don't see how to use those here.) If you only expect a limited number of sets, we could set up a limited number of rules (3 or 4?) that might work. Otherwise, you'll need a VBA macro to do this. Would that work for you? Even a macro though would require a list of the color values you want to highlight the cells with, so if you have a lot of sets, we'll probably end up repeating some colors. Let me know.
Hi Eric,
first of all thank you for your support

below are the answers to your questions

Could a number show up in the same column more than once? NO How many rows does your data have? Do you have any idea how many sets of 4 you might have? FROM 2 TO 10 I THINK

Conditional Formatting probably won't work for you, since each custom formula only allows 1 color. (Some built-in CF rules have multiple colors, but I don't see how to use those here.) If you only expect a limited number of sets, we could set up a limited number of rules (3 or 4?) That might work. Otherwise, you'll need a VBA macro to do this. Would that work for you?

Yes I have tried several solutions but I agree with you that I need a macro in VBA, I have found one that does a similar thing but I cannot modify it for my purpose

Thanks again
 
Upvote 0
OK, give this a shot:

Open a COPY of you workbook. Press Alt-F11 to open the VBA editor. Press Alt-IM to Insert a Module. Copy the following code into the window that opens:

VBA Code:
Sub Highlight4()
Dim ul As Range, d As Variant, colors As Variant, ctr As Long
Dim a1 As Long, a2 As Long, a3 As Long, a4 As Long

    Set ul = Range("A1")
    d = ul.Resize(ul.End(xlDown).Row - ul.Row + 1, 4).Value
   
    colors = Array(vbRed, vbYellow, RGB(20, 200, 40), 15773696)
    ctr = 0
    On Error GoTo NoMatch:
       
    For a1 = 1 To UBound(d)
        a2 = WorksheetFunction.Match(d(a1, 1), WorksheetFunction.Index(d, 0, 2), 0)
        a3 = WorksheetFunction.Match(d(a1, 1), WorksheetFunction.Index(d, 0, 3), 0)
        a4 = WorksheetFunction.Match(d(a1, 1), WorksheetFunction.Index(d, 0, 4), 0)
        ul.Offset(a1 - 1, 0).Interior.Color = colors(ctr)
        ul.Offset(a2 - 1, 1).Interior.Color = colors(ctr)
        ul.Offset(a3 - 1, 2).Interior.Color = colors(ctr)
        ul.Offset(a4 - 1, 3).Interior.Color = colors(ctr)
        ctr = (ctr + 1) Mod (UBound(colors) + 1)
NextA1:
    Next a1
   
    Exit Sub
   
NoMatch:
    Resume NextA1:
   
End Sub

In the first executable line, set the upper left corner of your range (A1 in this example). Two lines below that, put the colors you want to highlight with. I showed 3 ways to identify them. There are 8 colors you can identify with a vb constant: vbBlack, vbRed, vbGreen, vbYellow, vbBlue, vbMagenta, vbCyan, and vbWhite. Or you can use the RGB function to define a custom color, or just use the full number which you can find by looking at the range.interior.color property.

Now go back to Excel, press Alt-F8 to open the macro selector, choose Highlight4 and click Run. On your example, I got this result:

Book1
ABCD
160197661
211616460
362206110
440521067
577106919
667631820
79704870
882605030
916555376
1080306748
1122486052
1229253763
133349416
1486563082
1514863655
166667559
179051262
1843151612
1910318222
2057333564
2159547343
222367090
2330726373
2470231786
258572740
2615797824
2747877933
281961450
2949242414
3071124377
Sheet4


Note that 60 and 70 are both highlighted in red. This is because there are 5 sets, but I only defined 4 colors in the array, so the macro started reusing them. If you put additional colors in the array, this might not happen.

Good luck!
 
Upvote 0
Solution

Forum statistics

Threads
1,215,053
Messages
6,122,888
Members
449,097
Latest member
dbomb1414

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top