ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   VBA CODE FOR CONDITIONAL FORMULA (https://www.excelbanter.com/excel-programming/438141-vba-code-conditional-formula.html)

vicky

VBA CODE FOR CONDITIONAL FORMULA
 
hey i need a vba code for conditional formula .... i want to check
this 3 conditions for every cell through vba code ...

= 120 then red colour

<50 then orange
inbetween 50 and 120 then yellow colour

joel[_498_]

VBA CODE FOR CONDITIONAL FORMULA
 

This code should work. You have to limit the range otherwise to go
through the entire worksheet takes a long time. There are more than one
shade of the colors and I picked the Standard shade for each of the
colors.

Const RedColor = 3
Const YellowColor = 6
Const OrangeColor = 46

Set DataRange = Range("A1:D500")

For Each cell In DataRange
If cell < "" And IsNumeric(cell) Then

Select Case cell
Case Is < 50
cell.Interior.ColorIndex = OrangeColor
Case Is < 120
cell.Interior.ColorIndex = YellowColor
Case Else
cell.Interior.ColorIndex = RedColor
End Select
End If
Next cell


--
joel
------------------------------------------------------------------------
joel's Profile: 229
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=168094

Microsoft Office Help


OssieMac

VBA CODE FOR CONDITIONAL FORMULA
 
Hi again Vicky,

Not sure if you need it but the code can be enhanced to only include numeric
cells and exclude blank cells as below.

Sub ConditFormat()

'= 120 then red colour
'<50 then orange
'inbetween 50 and 120 then yellow

Dim c As Range

'Edit "Sheet1" to your sheet name
With Sheets("Sheet1")
For Each c In .UsedRange
If c.Value < "" And _
IsNumeric(c.Value) Then

Select Case c.Value
Case Is = 120
c.Interior.ColorIndex = 3
Case Is < 50
c.Interior.ColorIndex = 46
Case 50 To 120
c.Interior.ColorIndex = 6
End Select
End If
Next c
End With

End Sub

--
Regards,

OssieMac



vicky

VBA CODE FOR CONDITIONAL FORMULA
 
thanks a lot !!!!!


All times are GMT +1. The time now is 08:12 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com