View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Norman Jones Norman Jones is offline
external usenet poster
 
Posts: 5,302
Default Conditional format for labels

Hi Jan,

Try:
'=============
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Rng1 As Range
Dim Rng2 As Range

Set Rng1 = Me.Range("A1") '<<==== CHANGE
Set Rng2 = Me.Range("E2") '<<==== CHANGE

If Not Intersect(Target, Union(Rng1, Rng2)) Is Nothing Then
Select Case Rng1.Value / Rng2.Value
Case 1: Me.Label1.BackColor = &H80FFFF
Case 2: Me.Label1.BackColor = &HFF&
Case Else: Me.Label1.BackColor = &H8000000F
End Select
End If
End Sub
'<<=============

This is worksheet event code and should be pasted into the worksheets's code
module (not a standard module and not the workbook's ThisWorkbook module):

Right-click the worksheet's tab
Select 'View Code' from the menu and paste the code.
Alt-F11 to return to Excel.


---
Regards,
Norman


"Jan" wrote in message
...
Hi,

This is probably easier than I think...? Maybe this shouldn't even have
been
posted under Programming.

I have a label - created from the toolbox - that shows a value (taken from
a
specific cell). If this value is 50% of another cell-value, I'd like it to
change the background color to yellow. And if 100%, I'd like it to change
to
red.

Like a dashboard. Same principle as Conditional Formatting for cells, but
for labels instead.

Any help is highly appreciated,
Jan