PC Review


Reply
Thread Tools Rate Thread

Changing Font Color to White if Background is Black

 
 
Brian
Guest
Posts: n/a
 
      2nd Apr 2009
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 With Quote
 
 
 
 
Greg Glynn
Guest
Posts: n/a
 
      2nd Apr 2009
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" <gsp....@gmail.com> 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 changedto
> 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 With Quote
 
Brian
Guest
Posts: n/a
 
      2nd Apr 2009
Hi Greg,

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

Brian

"Greg Glynn" <(E-Mail Removed)> wrote in message
news:916cd1d4-e562-411b-83b6-(E-Mail Removed)...
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" <gsp....@gmail.com> 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 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
Need to change color back to white background, black type eileenosu Microsoft Word New Users 1 9th Nov 2009 09:41 AM
How can I create a label with white font on a black background? =?Utf-8?B?Z2FibG9keQ==?= Microsoft Word Document Management 2 12th Nov 2007 01:16 AM
Changing white font color to black on the desktop...nothing works! =?Utf-8?B?S2FyZW4gV29vZHM=?= Windows XP Customization 10 26th Oct 2007 08:45 PM
new e-mail font color is white - need to default to black =?Utf-8?B?TGVlIGluIE9jZWFuIEJlYWNo?= Microsoft Outlook Discussion 1 13th Jul 2005 02:08 AM
changing black & white video to color ones. teddyli Freeware 3 13th Feb 2004 03:55 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:30 PM.