Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 172
Default Font/CellInteriorColour

I am comparing font colour with cell interior colour.
When I colour the font black and use a black interior,
the function returns a true value. When I colour the font
white, against a white cell interior, I get an error.
Should I be using color.index instead? Or am I running
into a problem with one of the colours being
xlColorIndexAutomatic. If so, How do I ensure that the
comparison compares like numeric values to create the
correct boolean value for the funtion?

Public Function CellHasSameFontAndInteriorColour(rng As
Range)
Dim FontColour As Integer
Dim InteriorColour As Integer

With rng
FontColour = .Font.Color
InteriorColour = .Interior.Color

If FontColour = InteriorColour Then
CellHasSameFontAndInteriorColour = True
Else
CellHasSameFontAndInteriorColour = False
End If
End With

End Function
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Font/CellInteriorColour

Your variables need to be Longs.

But you can simplify it without variables

Public Function CellHasSameFontAndInteriorColour(rng As Range)
With rng
CellHasSameFontAndInteriorColour = _
.Font.Color = .Interior.Color
End With
End Function


--

HTH

RP
(remove nothere from the email address if mailing direct)


"ExcelMonkey" wrote in message
...
I am comparing font colour with cell interior colour.
When I colour the font black and use a black interior,
the function returns a true value. When I colour the font
white, against a white cell interior, I get an error.
Should I be using color.index instead? Or am I running
into a problem with one of the colours being
xlColorIndexAutomatic. If so, How do I ensure that the
comparison compares like numeric values to create the
correct boolean value for the funtion?

Public Function CellHasSameFontAndInteriorColour(rng As
Range)
Dim FontColour As Integer
Dim InteriorColour As Integer

With rng
FontColour = .Font.Color
InteriorColour = .Interior.Color

If FontColour = InteriorColour Then
CellHasSameFontAndInteriorColour = True
Else
CellHasSameFontAndInteriorColour = False
End If
End With

End Function



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 172
Default Font/CellInteriorColour

Thank-you once again. I may have to start paying you guys
for this education!

Kind Regards
EM


-----Original Message-----
Your variables need to be Longs.

But you can simplify it without variables

Public Function CellHasSameFontAndInteriorColour(rng As

Range)
With rng
CellHasSameFontAndInteriorColour = _
.Font.Color = .Interior.Color
End With
End Function


--

HTH

RP
(remove nothere from the email address if mailing direct)


"ExcelMonkey" wrote

in message
...
I am comparing font colour with cell interior colour.
When I colour the font black and use a black interior,
the function returns a true value. When I colour the

font
white, against a white cell interior, I get an error.
Should I be using color.index instead? Or am I running
into a problem with one of the colours being
xlColorIndexAutomatic. If so, How do I ensure that the
comparison compares like numeric values to create the
correct boolean value for the funtion?

Public Function CellHasSameFontAndInteriorColour(rng As
Range)
Dim FontColour As Integer
Dim InteriorColour As Integer

With rng
FontColour = .Font.Color
InteriorColour = .Interior.Color

If FontColour = InteriorColour Then
CellHasSameFontAndInteriorColour = True
Else
CellHasSameFontAndInteriorColour = False
End If
End With

End Function



.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,163
Default Font/CellInteriorColour

I think your problem comes from the fact that the .Color property is a long
integer value; black is zero so that works but white is out of bounds for an
integer - try a Double instead

"ExcelMonkey" wrote:

I am comparing font colour with cell interior colour.
When I colour the font black and use a black interior,
the function returns a true value. When I colour the font
white, against a white cell interior, I get an error.
Should I be using color.index instead? Or am I running
into a problem with one of the colours being
xlColorIndexAutomatic. If so, How do I ensure that the
comparison compares like numeric values to create the
correct boolean value for the funtion?

Public Function CellHasSameFontAndInteriorColour(rng As
Range)
Dim FontColour As Integer
Dim InteriorColour As Integer

With rng
FontColour = .Font.Color
InteriorColour = .Interior.Color

If FontColour = InteriorColour Then
CellHasSameFontAndInteriorColour = True
Else
CellHasSameFontAndInteriorColour = False
End If
End With

End Function

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
Changing Font color based on font type or size John Excel Discussion (Misc queries) 2 February 7th 08 12:50 AM
Change all text one font size up with various font sizes used. omchrystal New Users to Excel 2 March 6th 07 09:01 PM
Changed default font, previous font still shows when editing Font/Editing Problem Excel Discussion (Misc queries) 1 May 19th 06 12:46 PM
Changed default font, previous font still shows when editing Font/Editing Problem Excel Discussion (Misc queries) 0 May 18th 06 04:37 PM
Dropdown list for font size, font type and number formats ExcelMonkey[_190_] Excel Programming 1 March 9th 05 03:50 PM


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

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"