Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 52
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default 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


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 52
Default VBA CODE FOR CONDITIONAL FORMULA

thanks a lot !!!!!
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Code to conditional format all black after date specified in code? wx4usa Excel Discussion (Misc queries) 3 December 26th 08 07:06 PM
Code for conditional formula Frederic Excel Programming 1 June 30th 05 06:10 AM
Multiple conditional on conditional format formula Frank Kabel Excel Programming 1 July 27th 04 06:24 PM
Multiple conditional on conditional format formula Bob Phillips[_7_] Excel Programming 0 July 27th 04 05:30 PM
Modify a conditional format formula in code? Shaun[_3_] Excel Programming 5 July 27th 04 12:56 AM


All times are GMT +1. The time now is 06:09 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"