Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Jan Jan is offline
external usenet poster
 
Posts: 159
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
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



  #3   Report Post  
Posted to microsoft.public.excel.programming
Jan Jan is offline
external usenet poster
 
Posts: 159
Default 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




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default 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



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
Format Data Labels ela Excel Worksheet Functions 0 April 24th 10 03:20 PM
Conditional Series Labels in Charts KMH Charts and Charting in Excel 0 December 9th 08 04:11 PM
Chart Labels - Conditional Formating Scott Charts and Charting in Excel 1 September 13th 08 10:03 AM
New Conditional Format Overriding Previous Conditional Format Rene Excel Discussion (Misc queries) 3 February 27th 08 06:08 PM
Conditional Formatting - Data Labels JEFF Charts and Charting in Excel 2 May 30th 07 04:18 AM


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