Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Changing Font Color to White if Background is Black

Hello,

I had a question answered , and code supplied. Works great. Now when I put 1
in a cell to change the background to black, the font needs to be changed to
white so I can see it, and if it's any other color than black keep the font
black.

I have something like

If valuess(i)=1 then
Font.ColorIndex=2 (white)
Interior.ColorIndex=1 (black)
Else
Font.ColorIndex=1 (black)
Interior.ColorIndex=valuess(i)
End If

I need to incorporate this into the code that was supplied. Thanks for any
help.



Private Sub Worksheet_Change(ByVal Target As Range)

Dim WatchRange As Range
Dim CellVal As String

If Target.Cells.Count 1 Then Exit Sub
If Target = "" Then Exit Sub
CellVal = Target
Set WatchRange = Range("F1:F100") 'change to suit

If Not Intersect(Target, WatchRange) Is Nothing Then
Set T = Target
codes = Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
valuess = Array(1, 2, 3, 6, 10, 16, 17, 23, 38, 46)
v = T.Value
For i = 0 To 9
If v = codes(i) Then
Application.EnableEvents = False
T.EntireRow.Resize(1, 5).Interior.ColorIndex = valuess(i)
Application.EnableEvents = True
Exit Sub
End If
Next
End If

End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 137
Default Changing Font Color to White if Background is Black

Hi Brian,

Might I suggest that you're over-complicating this? Does Conditional
Formatting get you the same result?

Greg

On Apr 2, 10:18*am, "Brian" wrote:
Hello,

I had a question answered , and code supplied. Works great. Now when I put 1
in a cell to change the background to black, the font needs to be changed to
white so I can see it, and if it's any other color than black keep the font
black.

I have something like

If valuess(i)=1 then
* *Font.ColorIndex=2 (white)
* *Interior.ColorIndex=1 (black)
Else
* *Font.ColorIndex=1 (black)
* *Interior.ColorIndex=valuess(i)
End If

I need to incorporate this into the code that was supplied. Thanks for any
help.

Private Sub Worksheet_Change(ByVal Target As Range)

Dim WatchRange As Range
Dim CellVal As String

If Target.Cells.Count 1 Then Exit Sub
If Target = "" Then Exit Sub
CellVal = Target
Set WatchRange = Range("F1:F100") 'change to suit

If Not Intersect(Target, WatchRange) Is Nothing Then
* * Set T = Target
* * codes = Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
* * valuess = Array(1, 2, 3, 6, 10, 16, 17, 23, 38, 46)
* * v = T.Value
* * For i = 0 To 9
* * * * If v = codes(i) Then
* * * * Application.EnableEvents = False
* * * * T.EntireRow.Resize(1, 5).Interior.ColorIndex = valuess(i)
* * * * Application.EnableEvents = True
* * * * Exit Sub
* * * * End If
* * Next
End If

End Sub


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Changing Font Color to White if Background is Black

Hi Greg,

Thanks, you're right. That's much simpler

Brian

"Greg Glynn" wrote in message
...
Hi Brian,

Might I suggest that you're over-complicating this? Does Conditional
Formatting get you the same result?

Greg

On Apr 2, 10:18 am, "Brian" wrote:
Hello,

I had a question answered , and code supplied. Works great. Now when I put
1
in a cell to change the background to black, the font needs to be changed
to
white so I can see it, and if it's any other color than black keep the
font
black.

I have something like

If valuess(i)=1 then
Font.ColorIndex=2 (white)
Interior.ColorIndex=1 (black)
Else
Font.ColorIndex=1 (black)
Interior.ColorIndex=valuess(i)
End If

I need to incorporate this into the code that was supplied. Thanks for any
help.

Private Sub Worksheet_Change(ByVal Target As Range)

Dim WatchRange As Range
Dim CellVal As String

If Target.Cells.Count 1 Then Exit Sub
If Target = "" Then Exit Sub
CellVal = Target
Set WatchRange = Range("F1:F100") 'change to suit

If Not Intersect(Target, WatchRange) Is Nothing Then
Set T = Target
codes = Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
valuess = Array(1, 2, 3, 6, 10, 16, 17, 23, 38, 46)
v = T.Value
For i = 0 To 9
If v = codes(i) Then
Application.EnableEvents = False
T.EntireRow.Resize(1, 5).Interior.ColorIndex = valuess(i)
Application.EnableEvents = True
Exit Sub
End If
Next
End If

End Sub


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
Color doesn't display -all black & white Sally in Cleveland Excel Worksheet Functions 0 May 16th 08 01:35 PM
Case Statement for Changing Font AND Background Color jjones Excel Programming 11 December 19th 07 07:11 PM
change color to black and white in excel 2003 John Charts and Charting in Excel 0 March 28th 07 02:43 AM
color page display black and white shelbo Excel Worksheet Functions 0 August 10th 06 06:13 PM
black background with white spots in the texture steve Excel Discussion (Misc queries) 0 August 6th 05 01:36 AM


All times are GMT +1. The time now is 09:28 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright 2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"