Fill colours in 3 columns conditional subject

motilulla

Well-known Member
Joined
Feb 13, 2008
Messages
2,422
Office Version
  1. 2010
Hello,

I want to be filled colour in columns E, F, G if in 3 consecutive rows find any values

Example1-F8, G9, E10 in 3 of the column and in 3 consecutive rows find some values fill colour in it.

Example2-E15, F16, G17 in 3 of the column and in 3 consecutive rows find some values fill colour in it.

Example3-G17, F18, E19 in 3 of the column and in 3 consecutive rows find some values fill colour in it.

Sample sheet attached


Book1
DEFGH
1
2
3
4
5n1n2n3
6
7
83
91
101
11
122
13
14
153
161
171
181
192
20
212
221
231
241
251
261
27
281
29
306
311
321
331
341
35
36
373
381
391
401
41
422
43
442
451
461
471
48
49
50
515
521
531
541
551
56
572
581
591
601
61
62
633
64
652
661
67
Sheet1


Thank you all
Excel 2000
Regards,
Moti
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Try this:-
Code:
[COLOR="Navy"]Sub[/COLOR] MG04Nov49
[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] n [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long[/COLOR]
[COLOR="Navy"]Dim[/COLOR] nRng [COLOR="Navy"]As[/COLOR] Range, Col [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] Rw [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long[/COLOR]
Rw = UsedRange.Rows.Count
[COLOR="Navy"]Set[/COLOR] Rng = Range("E6").Resize(Rw)
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng
    [COLOR="Navy"]For[/COLOR] n = 0 To 2
        [COLOR="Navy"]For[/COLOR] Ac = 0 To 2
            [COLOR="Navy"]If[/COLOR] Dn.Offset(n, Ac) <> "" [COLOR="Navy"]Then[/COLOR]
                 [COLOR="Navy"]If[/COLOR] nRng [COLOR="Navy"]Is[/COLOR] Nothing [COLOR="Navy"]Then[/COLOR]
                    [COLOR="Navy"]Set[/COLOR] nRng = Dn.Offset(n, Ac)
                 [COLOR="Navy"]Else[/COLOR]
                    [COLOR="Navy"]Set[/COLOR] nRng = Union(nRng, Dn.Offset(n, Ac))
                [COLOR="Navy"]End[/COLOR] If
              Col = Col + Dn.Offset(n, Ac).Column - 4
            [COLOR="Navy"]End[/COLOR] If
        [COLOR="Navy"]Next[/COLOR] Ac
    [COLOR="Navy"]Next[/COLOR] n
    [COLOR="Navy"]If[/COLOR] Not nRng [COLOR="Navy"]Is[/COLOR] Nothing [COLOR="Navy"]Then[/COLOR]
    [COLOR="Navy"]If[/COLOR] nRng.Count = 3 And Col = 6 [COLOR="Navy"]Then[/COLOR]
        nRng.Interior.Color = vbRed
    [COLOR="Navy"]End[/COLOR] If
        [COLOR="Navy"]Set[/COLOR] nRng = Nothing: Col = 0
    [COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR] Dn
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
If your running from Macro dialog box, you will probably need:-
Code:
Rw = Activesheet.Usedrange.Rows.count
 
Upvote 0
If your running from Macro dialog box, you will probably need:-
Code:
Rw = Activesheet.Usedrange.Rows.count
MickG, much appreciated no errors working excellent!

Have a good weekend

Regards,
Moti

 
Upvote 0

Forum statistics

Threads
1,223,948
Messages
6,175,570
Members
452,652
Latest member
eduedu

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