Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How to conditional color a named range in VBA code

I have a named 5x5 range called Costs in a VBA macro. I'd like
to fill the cells with a different color depending on their value.

For example

Sub Macro1()'
Dim Costs As Variant
Costs = Range("G2:K6").Select
If Range.["Costs"] Then
Select Case Range("Costs").Value
Case Is <= 5: Target.Interior.Color = eColors.green
Case Is <= 10: Target.Interior.Color = eColors.orange
Case Is <= 15: Target.Interior.Color = eColors.yellow
Case Else: Target.Interior.Color = eColors.red
End Select
End If
End Sub

Right now its not compiling any ideas?
--
mark
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default How to conditional color a named range in VBA code

It doen't compile because there isn't much that is correct about it. This
ran for me.

Sub Macro1() '
Dim cell As Range
Range("G2:K6").Name = "Costs"
For Each cell In Range("Costs")
Select Case cell.Value
Case Is <= 5: cell.Interior.Color = vbGreen
Case Is <= 10: cell.Interior.Color = 52479
Case Is <= 15: cell.Interior.Color = vbYellow
Case Else: cell.Interior.Color = vbRed
End Select
Next
End Sub
--
Regards,
Tom Ogilvy


"mark engineer" wrote in message
...
I have a named 5x5 range called Costs in a VBA macro. I'd like
to fill the cells with a different color depending on their value.

For example

Sub Macro1()'
Dim Costs As Variant
Costs = Range("G2:K6").Select
If Range.["Costs"] Then
Select Case Range("Costs").Value
Case Is <= 5: Target.Interior.Color = eColors.green
Case Is <= 10: Target.Interior.Color = eColors.orange
Case Is <= 15: Target.Interior.Color = eColors.yellow
Case Else: Target.Interior.Color = eColors.red
End Select
End If
End Sub

Right now its not compiling any ideas?
--
mark



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
Conditional sum in a named range Duane Excel Discussion (Misc queries) 8 September 30th 09 08:05 PM
Conditional formatting 'Named Range' dilemma Blue Max Excel Worksheet Functions 4 December 22nd 08 09:16 PM
VBA code to affect value of a named range Dave O Excel Discussion (Misc queries) 5 August 25th 06 10:12 PM
named range, conditional formatting drabbacs[_2_] Excel Programming 3 May 17th 05 06:12 PM
Named Range Fails in VBA Code Dean Hinson[_3_] Excel Programming 3 January 24th 05 03:48 PM


All times are GMT +1. The time now is 08:18 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"