PC Review


Reply
Thread Tools Rate Thread

AP Conditional Formatting

 
 
Antonio
Guest
Posts: n/a
 
      3rd Jun 2008
need to create a five-colour format macro for excel 2003. The conditons are:
B6=sum(B1:B5);
if B6<=55, then A1="Blue" (A1 filling should be dark blue and font should be
bold white);
if B6<=65, then A1="Green"(A1 filling should be dark green and font should
be bold white);
if B6<=75, then A1="Gold" (A1 filling should be gold and font should be bold
black);
if B6<=85, then A1="Extra" (A1 filling should be gray and font should be
bold black);
if B6<=100, then A1="Premiun" (A1 filling should be black and font should be
bold white);
Suggestions I was given so far haven't worked.
 
Reply With Quote
 
 
 
 
Bob Phillips
Guest
Posts: n/a
 
      3rd Jun 2008
'-----------------------------------------------------------------
Private Sub Worksheet_Change(ByVal Target As Range)
'-----------------------------------------------------------------
Const WS_RANGE As String = "B6" '<=== change to suit

On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
Select Case .Value
Case Is <= 55:
With Me.Range("A1")
.Value = "Blue"
.Interior.ColorIndex = 5
.Font.Color = vbWhite
.Font.Bold = True
End With
Case Is <= 65:
With Me.Range("A1")
.Value = "Green"
.Interior.ColorIndex = 10
.Font.Color = vbWhite
.Font.Bold = True
End With
Case Is <= 75:
With Me.Range("A1")
.Value = "Gold"
.Interior.ColorIndex = 44
.Font.Color = vbBlack
.Font.Bold = True
End With
Case Is <= 85:
With Me.Range("A1")
.Value = "Extra"
.Interior.ColorIndex = 16
.Font.Color = vbBlack
.Font.Bold = True
End With
Case Is <= 100:
With Me.Range("A1")
.Value = "Premium"
.Interior.Color = vbBlack
.Font.Color = vbWhite
.Font.Bold = True
End With
End Select
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub


'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.


--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Antonio" <(E-Mail Removed)> wrote in message
news:08B2FC48-8A21-4FC5-A171-(E-Mail Removed)...
> need to create a five-colour format macro for excel 2003. The conditons
> are:
> B6=sum(B1:B5);
> if B6<=55, then A1="Blue" (A1 filling should be dark blue and font should
> be
> bold white);
> if B6<=65, then A1="Green"(A1 filling should be dark green and font should
> be bold white);
> if B6<=75, then A1="Gold" (A1 filling should be gold and font should be
> bold
> black);
> if B6<=85, then A1="Extra" (A1 filling should be gray and font should be
> bold black);
> if B6<=100, then A1="Premiun" (A1 filling should be black and font should
> be
> bold white);
> Suggestions I was given so far haven't worked.



 
Reply With Quote
 
Ron Rosenfeld
Guest
Posts: n/a
 
      3rd Jun 2008
On Tue, 3 Jun 2008 04:18:06 -0700, Antonio <(E-Mail Removed)>
wrote:

>need to create a five-colour format macro for excel 2003. The conditons are:
>B6=sum(B1:B5);
>if B6<=55, then A1="Blue" (A1 filling should be dark blue and font should be
>bold white);
>if B6<=65, then A1="Green"(A1 filling should be dark green and font should
>be bold white);
>if B6<=75, then A1="Gold" (A1 filling should be gold and font should be bold
>black);
>if B6<=85, then A1="Extra" (A1 filling should be gray and font should be
>bold black);
>if B6<=100, then A1="Premiun" (A1 filling should be black and font should be
>bold white);
>Suggestions I was given so far haven't worked.


It sure would be helpful if you would let us know what the previous suggestions
were and what happened with the previous suggestions. What does "didn't work"
mean?

Computer crash? Program crash? Maybe you just didn't implement one of those
suggestions properly.

Here's one suggestion, but I have no idea if you've tried it before or not, or
even what version of Excel you are using.


If you are using Excel 2007, you can use the built-in conditional formatting.

Otherwise, you will need to use an event triggered macro.

To enter this, right click on the sheet tab and select "View Code"

Paste the code below into the window that opens.

You can tweak the RGB values for the non-primary colors, or use the colorindex
property.

Note the the RGB colors, according to the HELP screen, will not work on
Macintosh. I'd guess the actual values would, though, and they are in comments
after the RGB property.

===========================================
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
With Range("A1")
Select Case Range("B6")
Case Is <= 55
.Value = "Blue"
.Interior.Color = vbBlue
.Font.Color = vbWhite
.Font.Bold = True
Case Is <= 65
.Value = "Green"
.Interior.Color = vbGreen
.Font.Color = vbWhite
.Font.Bold = True
Case Is <= 75
.Value = "Gold"
.Interior.Color = RGB(255, 204, 0) '52479
.Font.Color = vbBlack
.Font.Bold = True
Case Is <= 85
.Value = "Extra"
.Interior.Color = RGB(191, 191, 191) '12566272
.Font.Color = vbBlack
.Font.Bold = True
Case Is <= 100
.Value = "Premium"
.Interior.Color = vbBlack
.Font.Color = vbWhite
.Font.Bold = True
Case Else
.Clear
End Select
End With
Application.EnableEvents = True
End Sub
==============================
--ron
 
Reply With Quote
 
Ron Rosenfeld
Guest
Posts: n/a
 
      3rd Jun 2008
On Tue, 3 Jun 2008 12:42:00 +0100, "Bob Phillips" <(E-Mail Removed)>
wrote:

> If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
> With Target


Bob,

In my limited testing, this doesn't work if Me.Range(WS_RANGE) contains a
formula, and the precedent cell is changed.

Is there some efficient method of handling this, rather than firing the macro
for every change?
--ron
 
Reply With Quote
 
Bob Phillips
Guest
Posts: n/a
 
      3rd Jun 2008
I think you are right Ron, I only spotted the A1 twist at the end and added
it without testing.

Your approach is more robust.

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Ron Rosenfeld" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> On Tue, 3 Jun 2008 12:42:00 +0100, "Bob Phillips" <(E-Mail Removed)>
> wrote:
>
>> If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
>> With Target

>
> Bob,
>
> In my limited testing, this doesn't work if Me.Range(WS_RANGE) contains a
> formula, and the precedent cell is changed.
>
> Is there some efficient method of handling this, rather than firing the
> macro
> for every change?
> --ron



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Conditional Formatting of text effecting formatting of background =?Utf-8?B?SEFI?= Microsoft Access Reports 6 25th Mar 2008 06:23 PM
Protect Cell Formatting including Conditional Formatting =?Utf-8?B?TWljayBKZW5uaW5ncw==?= Microsoft Excel Misc 5 13th Nov 2007 05:32 PM
Conditional Formatting No Longer Conditional in 2007 Beta =?Utf-8?B?Q2FjdHVhci1Oby1KdXRzdQ==?= Microsoft Excel Crashes 0 17th Nov 2006 10:01 PM
How do I do a complex conditional in a conditional formatting formula Ray Stevens Microsoft Excel Discussion 7 12th Mar 2006 10:24 PM
Conditional Formatting that will display conditional data =?Utf-8?B?QnJhaW5GYXJ0?= Microsoft Excel Worksheet Functions 1 13th Sep 2005 05:45 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:06 PM.