How to conditional color a named range in VBA code

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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?
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top