LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default VBA code for 5-rule Conditional Formating

'-----------------------------------------------------------------
Private Sub Worksheet_Change(ByVal Target As Range)
'-----------------------------------------------------------------
Const WS_RANGE As String = "A1" '<=== change to suit
Dim ci As Long

On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
Select Case .Value
Case 0: ci = vbBlack
Case 1: ci = 10 'green
Case 2: ci = 15 'gray 25%
Case 3: ci = 5 'blue
Case 4: ci = 44 'gold
End Select
.Offset(1, 0).Interior.ColorIndex = ci
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.



--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)



"Antonio" wrote in message
...
Would anyone have a VAb code for a macro that changes the color of a cell
according to 5 different rules? A2 would be black if A1=1, green if A1=2,
gray if A1=3, blue if A1=4 or gold if A1=5.
Thanks



 
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
Conditional Formatting Applying Rule to Entire Column Vince Pacella Excel Discussion (Misc queries) 2 December 1st 09 09:00 AM
Conditional formatting rule precedence difficulties Luke Excel Discussion (Misc queries) 4 August 28th 09 08:27 PM
Expanding Conditional Format Rule to entire Column KKD Excel Discussion (Misc queries) 1 May 27th 09 07:58 PM
Copying Conditional Formatting rule Hartmut \(Harry\) Kloppert Excel Worksheet Functions 1 April 21st 09 02:28 AM
Conditional formating or Macro code [email protected] Excel Discussion (Misc queries) 3 June 14th 07 04:30 PM


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

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

About Us

"It's about Microsoft Excel"