ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Conditional format for labels (https://www.excelbanter.com/excel-programming/354272-conditional-format-labels.html)

Jan

Conditional format for labels
 
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

Norman Jones

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




Jan

Conditional format for labels
 
Thanks, Norman. Great, fast reponse. The code even seems to make sense to an
amateur like me ! ;-)

I still seem to be missing out on a detail somewhere, though, as I get the
following message:

'Compile Error: Method or datamember not found'
and then a highlighting of '.Label1' in the line Case 1: Me.Label1.BackColor
= &H80FFFF ?

I thought this was regards the naming of my label, but it is called Label1 -
or how can I be sure. I'm just looking in the upper-left corner when
highlighting the label and it says 'Label1'?

Regards,
Jan

"Norman Jones" wrote:

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





Norman Jones

Conditional format for labels
 
Hi Jan,

If you wish, you may send me your workbook:

norman_jones@NOSPAMbtconnectDOTcom

(Delete "NOSPAM" and replace"DOT" with a period (full stop))

By all means, delete other sheets and any sensitive data.

---
Regards,
Norman



"Jan" wrote in message
...
Thanks, Norman. Great, fast reponse. The code even seems to make sense to
an
amateur like me ! ;-)

I still seem to be missing out on a detail somewhere, though, as I get the
following message:

'Compile Error: Method or datamember not found'
and then a highlighting of '.Label1' in the line Case 1:
Me.Label1.BackColor
= &H80FFFF ?

I thought this was regards the naming of my label, but it is called
Label1 -
or how can I be sure. I'm just looking in the upper-left corner when
highlighting the label and it says 'Label1'?

Regards,
Jan





All times are GMT +1. The time now is 12:20 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com