Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Value based Text Colors

I have been trying to set a range of cells Text colors based on the value in
the cell. I need the color to change as the data is being entered. When I
use the "Worksheet_Change(ByVal Target As Range)" function I cannot set a
specific range, any cell on the sheet changes when I enter data.

I would prefer not to loop through the range checking each cell since this
not only takes time, it is not immediate either.

Any help would be greatly appreciated.

John


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Value based Text Colors

Private Sub Worksheet_Change(ByVal Target As Range)
if Target.count 1 then exit sub
if not intersect(target,Range("A1:B10")) is nothing then
' color the cell based on condition
end if
End Sub

this works on the specified cells: A1:B10

I have written it to do nothing if multiple cells are changed
simultaneously. You may prefer to handle this event

Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng as Range, cell as Range
if not intersect(target,Range("A1:B10")) is nothing then
set rng = Intersect(Target,Range("A1:B10")
for each cell in rng
' color the cell based on condition
Next
end if
End Sub


--
Regards,
Tom Ogilvy


"JohnH" wrote in message
nk.net...
I have been trying to set a range of cells Text colors based on the value

in
the cell. I need the color to change as the data is being entered. When

I
use the "Worksheet_Change(ByVal Target As Range)" function I cannot set a
specific range, any cell on the sheet changes when I enter data.

I would prefer not to loop through the range checking each cell since this
not only takes time, it is not immediate either.

Any help would be greatly appreciated.

John




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Value based Text Colors

This works great: My Final code looks like this:

Option Explicit
Enum eColors
Black = 1
Red = 3
Blue = 5
Maroon = 9
End Enum

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target,
Range("C5:D28,C31:D34,G5:H28,G31:G34,N5:O28,N31:O3 4,R5:S28,R31:S34")) Is
Nothing Then
Select Case
Intersect(Range("C5:D28,C31:D34,G5:H28,G31:G34,N5: O28,N31:O34,R5:S28,R31:S34"),
Target)
Case ""
Target.Font.Bold = False
Target.Font.ColorIndex = Black
Case "Open"
Target.Font.Bold = True
Target.Font.ColorIndex = Maroon
Case "OPEN"
Target.Font.Bold = True
Target.Font.ColorIndex = Maroon
Case "open"
Target.Font.Bold = True
Target.Font.ColorIndex = Maroon
Case Is -9
Target.Font.Bold = True
Target.Font.ColorIndex = Red
Case Is < -13.99
Target.Font.Bold = True
Target.Font.Italic = True
Target.Font.ColorIndex = Blue
Case Else
Target.Font.Bold = False
Target.Font.ColorIndex = Black
End Select
End If
End Sub


Thank you very much.





"Tom Ogilvy" wrote in message
...
Private Sub Worksheet_Change(ByVal Target As Range)
if Target.count 1 then exit sub
if not intersect(target,Range("A1:B10")) is nothing then
' color the cell based on condition
end if
End Sub

this works on the specified cells: A1:B10

I have written it to do nothing if multiple cells are changed
simultaneously. You may prefer to handle this event

Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng as Range, cell as Range
if not intersect(target,Range("A1:B10")) is nothing then
set rng = Intersect(Target,Range("A1:B10")
for each cell in rng
' color the cell based on condition
Next
end if
End Sub


--
Regards,
Tom Ogilvy


"JohnH" wrote in message
nk.net...
I have been trying to set a range of cells Text colors based on the value

in
the cell. I need the color to change as the data is being entered. When

I
use the "Worksheet_Change(ByVal Target As Range)" function I cannot set a
specific range, any cell on the sheet changes when I enter data.

I would prefer not to loop through the range checking each cell since
this
not only takes time, it is not immediate either.

Any help would be greatly appreciated.

John






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Value based Text Colors

Hi

When I use the "Worksheet_Change(ByVal Target As Range)" function I cannot set a specific range, any cell on the sheet changes when
I enter data.


You can use a range like this

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Application.Intersect(Range("A1:A20"), Target) Is Nothing Then
YourMacroName
End If
End Sub




--
Regards Ron de Bruin
http://www.rondebruin.nl


"JohnH" wrote in message nk.net...
I have been trying to set a range of cells Text colors based on the value in the cell. I need the color to change as the data is
being entered. When I use the "Worksheet_Change(ByVal Target As Range)" function I cannot set a specific range, any cell on the
sheet changes when I enter data.

I would prefer not to loop through the range checking each cell since this not only takes time, it is not immediate either.

Any help would be greatly appreciated.

John



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Value based Text Colors

look under Format / Conditional Format. It will answer your question!
d

"JohnH" wrote:

I have been trying to set a range of cells Text colors based on the value in
the cell. I need the color to change as the data is being entered. When I
use the "Worksheet_Change(ByVal Target As Range)" function I cannot set a
specific range, any cell on the sheet changes when I enter data.

I would prefer not to loop through the range checking each cell since this
not only takes time, it is not immediate either.

Any help would be greatly appreciated.

John





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
Worksheet formatting (fill colors & text colors) disappeared sweettooth Excel Discussion (Misc queries) 2 June 24th 08 01:16 AM
How do I set cell colors based on if query Wullie Excel Worksheet Functions 3 April 2nd 06 10:36 PM
How do I change row text colors in Excel based on formula? ggliddy Excel Discussion (Misc queries) 1 November 14th 05 07:27 PM
How do I fill row colors based on cell value? Daskeeper Excel Discussion (Misc queries) 1 January 31st 05 10:12 AM
Changing cell colors based on values Jon Willits Excel Programming 3 February 29th 04 08:06 PM


All times are GMT +1. The time now is 03:22 AM.

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"