Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Why doesn't the font color change?


With Dominic’s help, I added the Function “Protection()” to m
spreadsheet, which function displays the protection status for th
sheet. It updates only when a value is entered or when F9 is pressed
and that suits my application fine.

The function:

FUNCTION PROTECTION()
APPLICATION.VOLATILE TRUE
PROTECTION = \"UNPROTECTED\"
IF ACTIVEWORKBOOK.PROTECTSTRUCTURE = TRUE OR _
ACTIVESHEET.PROTECTCONTENTS = TRUE THEN
PROTECTION = \"PROTECTED\"
END IF
END FUNCTION

I also wanted to change the font color of the cell according to status
Unprotected would be red, and protected would be green.
For that, I tested the following macro, and it works fine when run as
macro; i.e., the fonts of the cells change to red and green.

SUB COLORINDECES()
CELLS(1,1).FONT.COLORINDEX = 3
CELLS(2,1).FONT.COLORINDEX = 4
END SUB

However, if I add the 'font-color lines' of the macro to the function
as shown below, the font colors don’t change. Why?

FUNCTION PROTECTION()
APPLICATION.VOLATILE TRUE
PROTECTION = \"UNPROTECTED\"
CELLS(1, 1).FONT.COLORINDEX = 3 'DISPLAY UNPROTECTED IN RED
IF ACTIVEWORKBOOK.PROTECTSTRUCTURE = TRUE OR _
ACTIVESHEET.PROTECTCONTENTS = TRUE THEN
PROTECTION = \"PROTECTED\"
CELLS(1, 1).FONT.COLORINDEX = 4 'DISPLAY PROTECTED IN GREEN
END IF
END FUNCTION


Thanks!

Ale

--
Ingeniero
-----------------------------------------------------------------------
Ingeniero1's Profile: http://www.excelforum.com/member.php...nfo&userid=402
View this thread: http://www.excelforum.com/showthread.php?threadid=37597

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Why doesn't the font color change?

Alex,

Functions can't change anything other than the value that they return to the
calling cell: not the color, not the font, nothing. You would need to use
either conditional formatting, a macro, or an event to change the color.

HTH,
Bernie
MS Excel MVP


"Ingeniero1" wrote
in message ...

With Dominic's help, I added the Function "Protection()" to my
spreadsheet, which function displays the protection status for the
sheet. It updates only when a value is entered or when F9 is pressed,
and that suits my application fine.

The function:

FUNCTION PROTECTION()
APPLICATION.VOLATILE TRUE
PROTECTION = \"UNPROTECTED\"
IF ACTIVEWORKBOOK.PROTECTSTRUCTURE = TRUE OR _
ACTIVESHEET.PROTECTCONTENTS = TRUE THEN
PROTECTION = \"PROTECTED\"
END IF
END FUNCTION

I also wanted to change the font color of the cell according to status:
Unprotected would be red, and protected would be green.
For that, I tested the following macro, and it works fine when run as a
macro; i.e., the fonts of the cells change to red and green.

SUB COLORINDECES()
CELLS(1,1).FONT.COLORINDEX = 3
CELLS(2,1).FONT.COLORINDEX = 4
END SUB

However, if I add the 'font-color lines' of the macro to the function,
as shown below, the font colors don't change. Why?

FUNCTION PROTECTION()
APPLICATION.VOLATILE TRUE
PROTECTION = \"UNPROTECTED\"
CELLS(1, 1).FONT.COLORINDEX = 3 'DISPLAY UNPROTECTED IN RED
IF ACTIVEWORKBOOK.PROTECTSTRUCTURE = TRUE OR _
ACTIVESHEET.PROTECTCONTENTS = TRUE THEN
PROTECTION = \"PROTECTED\"
CELLS(1, 1).FONT.COLORINDEX = 4 'DISPLAY PROTECTED IN GREEN
END IF
END FUNCTION


Thanks!

Alex


--
Ingeniero1
------------------------------------------------------------------------
Ingeniero1's Profile:

http://www.excelforum.com/member.php...fo&userid=4029
View this thread: http://www.excelforum.com/showthread...hreadid=375973



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Why doesn't the font color change?

Functions used in worksheet cells are not permitted to alter the excel
environment. They only return values to the cells, like any worksheet
function.

You can use conditional formatting under the format menu to change the font
color base on the value returned by your function.

--
Regards,
Tom Ogilvy

"Ingeniero1" wrote
in message ...

With Dominic's help, I added the Function "Protection()" to my
spreadsheet, which function displays the protection status for the
sheet. It updates only when a value is entered or when F9 is pressed,
and that suits my application fine.

The function:

FUNCTION PROTECTION()
APPLICATION.VOLATILE TRUE
PROTECTION = \"UNPROTECTED\"
IF ACTIVEWORKBOOK.PROTECTSTRUCTURE = TRUE OR _
ACTIVESHEET.PROTECTCONTENTS = TRUE THEN
PROTECTION = \"PROTECTED\"
END IF
END FUNCTION

I also wanted to change the font color of the cell according to status:
Unprotected would be red, and protected would be green.
For that, I tested the following macro, and it works fine when run as a
macro; i.e., the fonts of the cells change to red and green.

SUB COLORINDECES()
CELLS(1,1).FONT.COLORINDEX = 3
CELLS(2,1).FONT.COLORINDEX = 4
END SUB

However, if I add the 'font-color lines' of the macro to the function,
as shown below, the font colors don't change. Why?

FUNCTION PROTECTION()
APPLICATION.VOLATILE TRUE
PROTECTION = \"UNPROTECTED\"
CELLS(1, 1).FONT.COLORINDEX = 3 'DISPLAY UNPROTECTED IN RED
IF ACTIVEWORKBOOK.PROTECTSTRUCTURE = TRUE OR _
ACTIVESHEET.PROTECTCONTENTS = TRUE THEN
PROTECTION = \"PROTECTED\"
CELLS(1, 1).FONT.COLORINDEX = 4 'DISPLAY PROTECTED IN GREEN
END IF
END FUNCTION


Thanks!

Alex


--
Ingeniero1
------------------------------------------------------------------------
Ingeniero1's Profile:

http://www.excelforum.com/member.php...fo&userid=4029
View this thread: http://www.excelforum.com/showthread...hreadid=375973



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,120
Default Why doesn't the font color change?

Is this what you want

Function PROTECTION()
Application.Volatile True
With Cells(1, 1)
.Value = "UNPROTECTED\"
.Font.ColorIndex = 3 'DISPLAY UNPROTECTED IN RED
If ActiveWorkbook.ProtectStructure = True Or _
ActiveSheet.ProtectContents = True Then
.Value = "PROTECTED\"
.Font.ColorIndex = 4 'DISPLAY PROTECTED IN GREEN
End If
End With
End Function


--
HTH

Bob Phillips

"Ingeniero1" wrote
in message ...

With Dominic's help, I added the Function "Protection()" to my
spreadsheet, which function displays the protection status for the
sheet. It updates only when a value is entered or when F9 is pressed,
and that suits my application fine.

The function:

FUNCTION PROTECTION()
APPLICATION.VOLATILE TRUE
PROTECTION = \"UNPROTECTED\"
IF ACTIVEWORKBOOK.PROTECTSTRUCTURE = TRUE OR _
ACTIVESHEET.PROTECTCONTENTS = TRUE THEN
PROTECTION = \"PROTECTED\"
END IF
END FUNCTION

I also wanted to change the font color of the cell according to status:
Unprotected would be red, and protected would be green.
For that, I tested the following macro, and it works fine when run as a
macro; i.e., the fonts of the cells change to red and green.

SUB COLORINDECES()
CELLS(1,1).FONT.COLORINDEX = 3
CELLS(2,1).FONT.COLORINDEX = 4
END SUB

However, if I add the 'font-color lines' of the macro to the function,
as shown below, the font colors don't change. Why?

FUNCTION PROTECTION()
APPLICATION.VOLATILE TRUE
PROTECTION = \"UNPROTECTED\"
CELLS(1, 1).FONT.COLORINDEX = 3 'DISPLAY UNPROTECTED IN RED
IF ACTIVEWORKBOOK.PROTECTSTRUCTURE = TRUE OR _
ACTIVESHEET.PROTECTCONTENTS = TRUE THEN
PROTECTION = \"PROTECTED\"
CELLS(1, 1).FONT.COLORINDEX = 4 'DISPLAY PROTECTED IN GREEN
END IF
END FUNCTION


Thanks!

Alex


--
Ingeniero1
------------------------------------------------------------------------
Ingeniero1's Profile:

http://www.excelforum.com/member.php...fo&userid=4029
View this thread: http://www.excelforum.com/showthread...hreadid=375973



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Why doesn't the font color change?


Good afternoon Alex

You can't do this within a UDF I'm afraid. A UDF differs from a macro
in that you cannot change or format the sheet in any way. All you can
do is perform a calculation and insert it into a cell. However, you
could set your conditional formatting to change the cell a different
colour depending on the cell contents.

HTH

DominicB


--
dominicb
------------------------------------------------------------------------
dominicb's Profile: http://www.excelforum.com/member.php...o&userid=18932
View this thread: http://www.excelforum.com/showthread...hreadid=375973



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Why doesn't the font color change?


Dominic, Bernie, Tom -
Conditional formatting works fine. I just wanted to see if it could b
done from within the function itself - now I know better.
Thanks!

Tom,
I tried that, but XL gave me a 'circular reference' error when
entered the function reference at cell A1, and a 'Value' error whe
entered elsewhere.

Thanks all the same.

Ale

--
Ingeniero
-----------------------------------------------------------------------
Ingeniero1's Profile: http://www.excelforum.com/member.php...nfo&userid=402
View this thread: http://www.excelforum.com/showthread.php?threadid=37597

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,120
Default Why doesn't the font color change?

Sorry, missed the F9 bit.

--
HTH

Bob Phillips

"Bob Phillips" wrote in message
...
Is this what you want

Function PROTECTION()
Application.Volatile True
With Cells(1, 1)
.Value = "UNPROTECTED\"
.Font.ColorIndex = 3 'DISPLAY UNPROTECTED IN RED
If ActiveWorkbook.ProtectStructure = True Or _
ActiveSheet.ProtectContents = True Then
.Value = "PROTECTED\"
.Font.ColorIndex = 4 'DISPLAY PROTECTED IN GREEN
End If
End With
End Function


--
HTH

Bob Phillips

"Ingeniero1"

wrote
in message ...

With Dominic's help, I added the Function "Protection()" to my
spreadsheet, which function displays the protection status for the
sheet. It updates only when a value is entered or when F9 is pressed,
and that suits my application fine.

The function:

FUNCTION PROTECTION()
APPLICATION.VOLATILE TRUE
PROTECTION = \"UNPROTECTED\"
IF ACTIVEWORKBOOK.PROTECTSTRUCTURE = TRUE OR _
ACTIVESHEET.PROTECTCONTENTS = TRUE THEN
PROTECTION = \"PROTECTED\"
END IF
END FUNCTION

I also wanted to change the font color of the cell according to status:
Unprotected would be red, and protected would be green.
For that, I tested the following macro, and it works fine when run as a
macro; i.e., the fonts of the cells change to red and green.

SUB COLORINDECES()
CELLS(1,1).FONT.COLORINDEX = 3
CELLS(2,1).FONT.COLORINDEX = 4
END SUB

However, if I add the 'font-color lines' of the macro to the function,
as shown below, the font colors don't change. Why?

FUNCTION PROTECTION()
APPLICATION.VOLATILE TRUE
PROTECTION = \"UNPROTECTED\"
CELLS(1, 1).FONT.COLORINDEX = 3 'DISPLAY UNPROTECTED IN RED
IF ACTIVEWORKBOOK.PROTECTSTRUCTURE = TRUE OR _
ACTIVESHEET.PROTECTCONTENTS = TRUE THEN
PROTECTION = \"PROTECTED\"
CELLS(1, 1).FONT.COLORINDEX = 4 'DISPLAY PROTECTED IN GREEN
END IF
END FUNCTION


Thanks!

Alex


--
Ingeniero1
------------------------------------------------------------------------
Ingeniero1's Profile:

http://www.excelforum.com/member.php...fo&userid=4029
View this thread:

http://www.excelforum.com/showthread...hreadid=375973





  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Why doesn't the font color change?

Ingeniero,
I didn't offer anything but correct advice.

I think you want to "thanks all the same" to Bob.

No sense in disrespecting me.

--
Regards.
Tom govily

"Ingeniero1" wrote
in message ...

Dominic, Bernie, Tom -
Conditional formatting works fine. I just wanted to see if it could be
done from within the function itself - now I know better.
Thanks!

Tom,
I tried that, but XL gave me a 'circular reference' error when I
entered the function reference at cell A1, and a 'Value' error when
entered elsewhere.

Thanks all the same.

Alex


--
Ingeniero1
------------------------------------------------------------------------
Ingeniero1's Profile:

http://www.excelforum.com/member.php...fo&userid=4029
View this thread: http://www.excelforum.com/showthread...hreadid=375973



  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Why doesn't the font color change?

Hit the button too fast

"No sense in disrespecting me."

should have been

No sense in disrespecting me. <g

Sorry

--
Regards,
Tom Ogilvy


"Tom Ogilvy" wrote in message
...
Ingeniero,
I didn't offer anything but correct advice.

I think you want to "thanks all the same" to Bob.

No sense in disrespecting me.

--
Regards.
Tom govily

"Ingeniero1"

wrote
in message ...

Dominic, Bernie, Tom -
Conditional formatting works fine. I just wanted to see if it could be
done from within the function itself - now I know better.
Thanks!

Tom,
I tried that, but XL gave me a 'circular reference' error when I
entered the function reference at cell A1, and a 'Value' error when
entered elsewhere.

Thanks all the same.

Alex


--
Ingeniero1
------------------------------------------------------------------------
Ingeniero1's Profile:

http://www.excelforum.com/member.php...fo&userid=4029
View this thread:

http://www.excelforum.com/showthread...hreadid=375973





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
Checkbox to change background color, font color and remove/ add bo Sara Excel Discussion (Misc queries) 2 May 1st 23 11:43 AM
Cannot change font color or cell color Bezell Excel Discussion (Misc queries) 2 January 30th 09 06:12 PM
how can I conditionally change font color, or background color? MOHA Excel Worksheet Functions 3 August 21st 06 06:57 PM
How to change the default Border, Font Color, and Cell Color Elijah Excel Discussion (Misc queries) 3 November 2nd 05 11:52 PM
font color change Truseeker Excel Programming 2 July 1st 04 01:58 PM


All times are GMT +1. The time now is 08:39 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"