Highlight 3 diagonals

Kishan

Well-known Member
Joined
Mar 15, 2011
Messages
1,648
Office Version
  1. 2010
Platform
  1. Windows
Using Excel 2000

Hi,

I need to highlights 3 diagonals weather are they numbers or alphabets

In the example below check first column C to find diagonal in the column D & E

For example C6 is empty go for C7 if C7 is empty go for C8,
Yes find diagonal in C8, D9 & in E10 (in this case as in the row 8 find Diagonal check the complete row C8:P8 and highlight all diagonal) as found one more in the row 8 in cells M8, N10 & in O10 and continue same method to find all possible diagonal

Example data with numbers...


Book1
ABCDEFGHIJKLMNOP
1
2
3
4
5ROW NC1C2C3C4C5C6C7C8C9C10C11C12C13C14
66555
775555
8855555555
9955555555
10105555555
11115555
121255555
131355555555
14145555
151555555555
161655555555
17175555
181855555
1919555555555
2020555555
2121555555555
22225555555
23235555555
242455555555555
252555555
2626555555
272755555
2828555555555
292955555555
303055555
31315555555
32325555
333355555
34345555555
353555555555
363655555555
37375555555555
383855555555
3939555555
404055555
414155555555
4242555555
434355555555
44445555555555
45455555
46465555555
47475555555555
4848555555
494955555
505055555
51515555555555
52525555
5353555555555
54545555555
555555555
565655555555
57575555555
5858555555
59595555
60605555555
61615555
626255555555555
6363555555
6464555555
656555555555
66665555555
67675555555
6868555
696955555
7070555555
717155555
7272555555
7373555555
7474555555
757555555555
7676555555
777755
7878555
7979
8080
Sheet1


Example data with alphabets...


Book1
ABCDEFGHIJKLMNOP
1
2
3
4
5ROW NC1C2C3C4C5C6C7C8C9C10C11C12C13C14
66AAA
77AAAA
88AAAAAAAA
99AAAAAAAA
1010AAAAAAA
1111AAAA
1212AAAAA
1313AAAAAAAA
1414AAAA
1515AAAAAAAA
1616AAAAAAAA
1717AAAA
1818AAAAA
1919AAAAAAAAA
2020AAAAAA
2121AAAAAAAAA
2222AAAAAAA
2323AAAAAAA
2424AAAAAAAAAAA
2525AAAAA
2626AAAAAA
2727AAAAA
2828AAAAAAAAA
2929AAAAAAAA
3030AAAAA
3131AAAAAAA
3232AAAA
3333AAAAA
3434AAAAAAA
3535AAAAAAAA
3636AAAAAAAA
3737AAAAAAAAAA
3838AAAAAAAA
3939AAAAAA
4040AAAAA
4141AAAAAAAA
4242AAAAAA
4343AAAAAAAA
4444AAAAAAAAAA
4545AAAA
4646AAAAAAA
4747AAAAAAAAAA
4848AAAAAA
4949AAAAA
5050AAAAA
5151AAAAAAAAAA
5252AAAA
5353AAAAAAAAA
5454AAAAAAA
5555AAAAA
5656AAAAAAAA
5757AAAAAAA
5858AAAAAA
5959AAAA
6060AAAAAAA
6161AAAA
6262AAAAAAAAAAA
6363AAAAAA
6464AAAAAA
6565AAAAAAAA
6666AAAAAAA
6767AAAAAAA
6868AAA
6969AAAAA
7070AAAAAA
7171AAAAA
7272AAAAAA
7373AAAAAA
7474AAAAAA
7575AAAAAAAA
7676AAAAAA
7777AA
7878AAA
7979
8080
Sheet2


Thank you in advance

Kishan
 
Hi Mick, the code is colouring alternate column in 2 different colours yellow & lime but do not highlighting the diagonals.

Please could you check?

Thank you

Kishan
Sorry Mick, may be for some reason your code does not work properly might cell were containing formula or they were not empty total or containing conditional formatting formula. Trying it again on fresh page it works like a charm

Thank you so much for you help and my apologize not checking it properly

Good Luck

Regards
Kishan :)


 
Upvote 0

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
I need to highlights 3 diagonals weather are they numbers or alphabets

Is the coloring you show in the number table example correct for the cells range H21:L24 (do you really want that lone yellow cell in cell I21)?
 
Upvote 0
Is the coloring you show in the number table example correct for the cells range H21:L24 (do you really want that lone yellow cell in cell I21)?
Just to follow up, the reason I asked the above question is that you did not follow the same rule in the range C21:F25. So in order to give you a proper solution, we need to know which color set is the correct one. Note: I did not look at the other solutions, but I find it hard to believe they reproduced the same colors as you show for the two ranges I have identified above.
 
Upvote 0
Hi Rick

If I understand correctly the cell I21 is not a lone cell, it's part of the diagonal I21,J22,K23

It just happens that the next row also generate the diagonal J22,K23,L24 and so the cells J22 and K23 belong to the 2 diagonals.

You'd have to choose which would be the colours of J22 and K23, since they are part of 2 diagonals. In the case the OP chose the colour of the diagonal in the lower row, blue.
 
Upvote 0
Hi Rick

If I understand correctly the cell I21 is not a lone cell, it's part of the diagonal I21,J22,K23

It just happens that the next row also generate the diagonal J22,K23,L24 and so the cells J22 and K23 belong to the 2 diagonals.

You'd have to choose which would be the colours of J22 and K23, since they are part of 2 diagonals. In the case the OP chose the colour of the diagonal in the lower row, blue.
I understand that, but did you see what I wrote in my follow up in Message #13 (the OP does not follow the same "rule" for coloring those cells)? I'm just asking him to either explain why they should be different or tell us which the wrong coloring set (or, conversely, which is the correct coloring set).
 
Last edited:
Upvote 0
You're welcome
Glad it worked in the end.!!
I know the OP said your code worked for him, but it doesn't seem to work correctly for my. I do not get alternating colors (most of them are green with a small smattering of yellow ones mixed in). Also, in the two ranges I identified in Messages #12 and #13 (for the numbers table), your code colors them differently than the OP showed on my worksheet.
 
Last edited:
Upvote 0
I know the colouring is not quite correct, but as duel colours where not explicitly requested and as I failed to get a quick correct result, I rather lost interest. !!! As you do !! and thought the code As Is, could be acceptable.
The resulting multicolouring is really set of 3 overlapping.
 
Upvote 0
This is better !!!
Code:
[COLOR="Navy"]Sub[/COLOR] MG09Sep51
[COLOR="Navy"]Dim[/COLOR] Rng [COLOR="Navy"]As[/COLOR] Range, Dn [COLOR="Navy"]As[/COLOR] Range, Ac [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] col [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] c [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long[/COLOR]
[COLOR="Navy"]Dim[/COLOR] Tdn [COLOR="Navy"]As[/COLOR] Range, nDn [COLOR="Navy"]As[/COLOR] Range, fd [COLOR="Navy"]As[/COLOR] Boolean
[COLOR="Navy"]Set[/COLOR] Rng = Range(Range("C6"), Range("C" & Rows.Count).End(xlUp))
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng
    [COLOR="Navy"]For[/COLOR] Ac = 0 To 11
        [COLOR="Navy"]Set[/COLOR] nDn = Union(Dn.Offset(, Ac), Dn.Offset(1, Ac + 1), Dn.Offset(2, Ac + 2))
        [COLOR="Navy"]Set[/COLOR] Tdn = Union(Dn, Dn.Offset(1, 1), Dn.Offset(2, 2))
        [COLOR="Navy"]If[/COLOR] Application.CountA(Tdn) = 3 [COLOR="Navy"]Then[/COLOR]
            [COLOR="Navy"]If[/COLOR] Dn.Offset(, Ac).Column = 3 [COLOR="Navy"]Then[/COLOR]
                c = c + 1
                col = IIf(c Mod 2 = 0, vbGreen, vbYellow)
            [COLOR="Navy"]End[/COLOR] If
            [COLOR="Navy"]If[/COLOR] Application.CountA(nDn) = 3 [COLOR="Navy"]Then[/COLOR]
                nDn.Interior.Color = col
            [COLOR="Navy"]End[/COLOR] If
        [COLOR="Navy"]End[/COLOR] If
    
    [COLOR="Navy"]Next[/COLOR] Ac
[COLOR="Navy"]Next[/COLOR] Dn
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
I see your point now. Maybe there are inconsistencies in the colours, or else the OP will explain the logic.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,021
Latest member
Mohamed Magdi Tawfiq Emam

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