Use vba to format a cell green if >87.

haxxbb

New Member
Joined
Apr 27, 2011
Messages
7
Im making a report manualy today and i would like a vba to do it automaticly. <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
<o:p> </o:p>
I have want to have a conditional formatting on cells e8 to e35 to green if value over 77<o:p></o:p>
And another conditional formatting on cells f8 to f35 to green if over 90. <o:p></o:p>
<o:p> </o:p>
Seems fine enoght.. This is the reason why im posting here. <o:p></o:p>
<o:p> </o:p>
Format 1 if value in celle 8 to 35 is equal or over 77 set color green in cell. Its suppose to do this in colum e, h k and all the way to IO. So do one colum with format 1 ignore the next 2 colums, then do 1, ignore the next 2. Etc <o:p></o:p>
<o:p> </o:p>
Format 2 if value in celle 8 to 35 is equal or over 90 set color green in cell. Its suppose to do this in colum f, i l and all the way to IP. So do one colum with format 2 ignore the next to colums, then do 1, ignore the next to one. Etc <o:p></o:p>
<o:p> </o:p>
Cells in row 7 have value (in text) other then x and y, if you gonna use that please just write “xvalue” “xvalue” or something.<o:p></o:p>
<o:p> </o:p>
See pic it its still unclear. <o:p></o:p>
<o:p> </o:p>
http://img685.imageshack.us/i/mrexcel.png/<o:p></o:p>
<o:p> </o:p>
Thanks in advance<o:p></o:p>
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Code:
Sub CF_Green()

    Range("E8:F35").FormatConditions.Delete
    
    With Range("E8:E35")
        .FormatConditions.Add Type:=xlCellValue, Operator:=xlGreaterEqual, Formula1:="77"
        .FormatConditions(1).Interior.ColorIndex = 35 'Green
    End With
    
    With Range("F8:F35")
        .FormatConditions.Add Type:=xlCellValue, Operator:=xlGreaterEqual, Formula1:="90"
        .FormatConditions(1).Interior.ColorIndex = 35 'Green
    End With
    
    Range("D8:F35").Copy
    Range("G8:IP35").PasteSpecial xlPasteFormats, xlNone, False, False
    Application.CutCopyMode = True
    
End Sub
 
Upvote 0
Hi and welcome to the board!!!
Two rules for E8:IP35
Code:
=($E8>77)*MOD(Column(),3)=2
Code:
=($F8>90)*(MOD(COLUMN(),3)=0)

lenze
 
Upvote 0
Code:
Sub CF_Green()
 
    Range("E8:F35").FormatConditions.Delete
 
    With Range("E8:E35")
        .FormatConditions.Add Type:=xlCellValue, Operator:=xlGreaterEqual, Formula1:="77"
        .FormatConditions(1).Interior.ColorIndex = 35 'Green
    End With
 
    With Range("F8:F35")
        .FormatConditions.Add Type:=xlCellValue, Operator:=xlGreaterEqual, Formula1:="90"
        .FormatConditions(1).Interior.ColorIndex = 35 'Green
    End With
 
    Range("D8:F35").Copy
    Range("G8:IP35").PasteSpecial xlPasteFormats, xlNone, False, False
    Application.CutCopyMode = True
 
End Sub

thanks for the kode! But it didnt work. Seems to be working fine at the start, but later i puts the color in the wrong colums etc.
 
Upvote 0
Hi and welcome to the board!!!
Two rules for E8:IP35
Code:
=($E8>77)*MOD(Column(),3)=2
Code:
=($F8>90)*(MOD(COLUMN(),3)=0)

lenze

Im a newbie when it comes to this. Where do i put the code? i have tryed running it as a macro.

Thanks in advance.
 
Upvote 0
The above are Formulas, not code. They are to be used in conditional formatting. What version of Excel are you using??

lenze
 
Upvote 0
Highlight the cells E8:IP35. On the ribbon, choose Contional Formatting. Click new rule. Select "use a Formula to detemine which cells to format". Copy one of the formulas to the field. Repeat for the 2nd formula!!

lenze

lenze
 
Upvote 0

Forum statistics

Threads
1,215,106
Messages
6,123,124
Members
449,096
Latest member
provoking

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