Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Function calls a Sub to change the cell font color

Hi guys

I have written a function which returns a double but i want to call a
sub from within it which will set the font color of the cell

(in reality i want it to set the color of the ActiveCell)

Function foo(ByVal x as Double) as Double
..
..
if x 2 then
call setColorTo3()
foo = 123.456
else
call setColorTo1()
foo = 1.111
end if
..
..
End function


Sub setColorTo3()
Activecell.Select
With Selection.Font
.ColorIndex = 3
.Bold = True
End With
End Sub

Sub setColorTo1()
Activecell.Select
With Selection.Font
.ColorIndex = 1
.Bold = True
End With
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,440
Default Function calls a Sub to change the cell font color

Not possible. A function cannot change anything in worksheets or Excel
setting; it can just replace its call with a result.

--

Kind Regards,

Niek Otten

Microsoft MVP - Excel

"grahamd" wrote in message
om...
Hi guys

I have written a function which returns a double but i want to call a
sub from within it which will set the font color of the cell

(in reality i want it to set the color of the ActiveCell)

Function foo(ByVal x as Double) as Double
.
.
if x 2 then
call setColorTo3()
foo = 123.456
else
call setColorTo1()
foo = 1.111
end if
.
.
End function


Sub setColorTo3()
Activecell.Select
With Selection.Font
.ColorIndex = 3
.Bold = True
End With
End Sub

Sub setColorTo1()
Activecell.Select
With Selection.Font
.ColorIndex = 1
.Bold = True
End With
End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,440
Default Function calls a Sub to change the cell font color

But of course you can use conditional formatting to change the color

--

Kind Regards,

Niek Otten

Microsoft MVP - Excel

"grahamd" wrote in message
om...
Hi guys

I have written a function which returns a double but i want to call a
sub from within it which will set the font color of the cell

(in reality i want it to set the color of the ActiveCell)

Function foo(ByVal x as Double) as Double
.
.
if x 2 then
call setColorTo3()
foo = 123.456
else
call setColorTo1()
foo = 1.111
end if
.
.
End function


Sub setColorTo3()
Activecell.Select
With Selection.Font
.ColorIndex = 3
.Bold = True
End With
End Sub

Sub setColorTo1()
Activecell.Select
With Selection.Font
.ColorIndex = 1
.Bold = True
End With
End Sub



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Function calls a Sub to change the cell font color

Hi Niek

You said: "But of course you can use conditional formatting to change
the color"


Can you elaborate a little more

I showed a simplified function foo() but in reality a condition is set
in the function which determines foo's return value



Subsequently applying a format to each cell based on the value foo
returned wont really do my job -

thanks anyway


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Function calls a Sub to change the cell font color

Hi Graham,

There one or two ways of triggering a Sub from a UDF, I use for a variety of
purposes concerned with colour. Such as:
Formatting a range, customize palette, creating and displaying a swatch of a
few hundred colours. However these methods are not reliable for general
use, at least I have not been able to make them such.

For your purposes I would go with Niek Otten's suggestion and CF. If you
have a simple UDF you can probably adapt the formula to return a true/false
Condition. In the CF dialog change "Cell Value Is" to "Formula Is" and then
your adapted formula. You have three conditions to play with plus a fourth,
namely the cell format that is displayed if none of the conditions are true.

Alternatively refer your CF's to whatever is returned by your UDF's

Regards,
Peter

"graham d" wrote in message
...
Hi Niek

You said: "But of course you can use conditional formatting to change
the color"


Can you elaborate a little more

I showed a simplified function foo() but in reality a condition is set
in the function which determines foo's return value



Subsequently applying a format to each cell based on the value foo
returned wont really do my job -

thanks anyway


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



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
Cannot change font color or cell color Bezell Excel Discussion (Misc queries) 2 January 30th 09 06:12 PM
Reg. Change of font color in a cell Ravi Excel Worksheet Functions 1 June 27th 08 10:07 AM
Change font color in cell Peggy Excel Discussion (Misc queries) 2 June 24th 08 04:30 PM
how do i change row font color based on cell value in that row brianatkraft Excel Worksheet Functions 5 November 2nd 06 08:53 PM
How to change the default Border, Font Color, and Cell Color Elijah Excel Discussion (Misc queries) 3 November 2nd 05 11:52 PM


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