filling range with colour

vssa

New Member
Joined
Feb 18, 2012
Messages
16
Hi, im pretty new to vba and im trying to write a macro that will allow me to
1. get the mean average of numbers in a range
2. then colour fill the range depending on what the mean average is

so far ive managed to write in out in principal i was wandering if any one could guide me in the right direction ?

cheers

Code:
Sub mean_average_color()


color range b5:t5 red


if average of b8:t8 is < (1.5 * average b5:t5)
color b8:y8 red

if average of b8:t8 is > (1.5 * average b5:t5)
color b8:y8 blue

if average of b8:t8 is > (2.2 * average b5:t5)
color b8:y8 green



if average of b11:t11 is < (1.5 * average b5:t5)
color b11:y11 red

if average of b11:t11 is > (1.5 * average b5:t5)
color b11:y11 blue

if average of b11:t11 is > (2.2 * average b5:t5)
color b11:y11 green



if average of b14:t14 is < (1.5 * average b5:t5)
color b14:y14 red

if average of b14:t14 is > (1.5 * average b5:t5)
color b14:y14 blue

if average of b14:t14 is > (2.2 * average b5:t5)
color b14:y14 green




if average of b17:t17 is < (1.5 * average b5:t5)
color b17:y17 red

if average of b17:t17 is > (1.5 * average b5:t5)
color b17:y17 blue

if average of b17:t17 is > (2.2 * average b5:t5)
color b17:y17 green

End sub
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
vssa,

Here is some code that should help you on your way.
It will run as is but I leave it for you to complete.......

Code:
Sub mean_average_color()
On Error Resume Next
Range("B5:T5").Cells.Interior.ColorIndex = 3  'Red
Av1 = Application.WorksheetFunction.Average(Range("B5:T5"))
Av2 = Application.WorksheetFunction.Average(Range("B8:T8"))
If Av2 < 1.5 * Av1 Then Range("B8:Y8").Cells.Interior.ColorIndex = 3  'Red
If Av2 > 1.5 * Av1 Then Range("B8:Y8").Cells.Interior.ColorIndex = 4   'Green
If Av2 > 2.2 * Av1 Then Range("B8:Y8").Cells.Interior.ColorIndex = 5   'Blue
 
'*******
Av3 = Application.WorksheetFunction.Average(Range("B11:T11"))
If Av3 < 1.5 * Av1 Then Range("B11:Y11").Cells.Interior.ColorIndex = 3  'Red
If Av3 > 1.5 * Av1 Then Range("B11:Y11").Cells.Interior.ColorIndex = 4   'Green
If Av3 > 2.2 * Av1 Then Range("B11:Y11").Cells.Interior.ColorIndex = 5   'Blue
 
'*******
'etc etc
 
 
'if average of b14:t14 is < (1.5 * average b5:t5)
'Color b14: y14 Red
'if average of b14:t14 is > (1.5 * average b5:t5)
'Color b14: y14 blue
'if average of b14:t14 is > (2.2 * average b5:t5)
'Color b14: y14 green
 
 
'if average of b17:t17 is < (1.5 * average b5:t5)
'Color b17: y17 Red
'if average of b17:t17 is > (1.5 * average b5:t5)
'Color b17: y17 blue
'if average of b17:t17 is > (2.2 * average b5:t5)
'Color b17: y17 green
On Error GoTo 0
End Sub

Hope that helps.
 
Upvote 0

Forum statistics

Threads
1,216,007
Messages
6,128,244
Members
449,435
Latest member
Jahmia0616

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