PC Review


Reply
Thread Tools Rate Thread

Automatically control the font of a cell when a function is used

 
 
Subodh
Guest
Posts: n/a
 
      5th May 2010
I have a my custom function say myfun(arguments)
I would like that whenever I use this function in any cell of a
workbook (sheet)
there should be always be the same font lets say Times New Roman, the
font size to be 10, font color automatic.
I tried to make another sub that will check every time the sub is
entered and ensure that the cell is well
with the desired font type. But, I could not get through the sub.
Any help in this regard will be appreciated.
Thanks in advance.
 
Reply With Quote
 
 
 
 
OssieMac
Guest
Posts: n/a
 
      6th May 2010
I don't think that you can make changes to the worksheet from within the UDF
but you could use a Worksheet_Change event. It will only set the font when
you enter or change the formula and there is nothing to prevent the user
changing the format of the cell later.

Not sure of your expertise with VBA but just in case you need help. Right
click the worksheet tab and select View code and the VBA editor will open at
the worksheets code. Copy the code and paste into the worksheets code area.

Private Sub Worksheet_Change(ByVal Target As Range)
If (Left(LCase(Target.Formula), 6)) = "=myfun" Then
Target.Font.Bold = True
Target.Font.ColorIndex = 3 'Red font
End If
End Sub



--
Regards,

OssieMac


"Subodh" wrote:

> I have a my custom function say myfun(arguments)
> I would like that whenever I use this function in any cell of a
> workbook (sheet)
> there should be always be the same font lets say Times New Roman, the
> font size to be 10, font color automatic.
> I tried to make another sub that will check every time the sub is
> entered and ensure that the cell is well
> with the desired font type. But, I could not get through the sub.
> Any help in this regard will be appreciated.
> Thanks in advance.
> .
>

 
Reply With Quote
 
Subodh
Guest
Posts: n/a
 
      7th May 2010
On May 7, 1:04*am, OssieMac <Ossie...@discussions.microsoft.com>
wrote:
> I don't think that you can make changes to the worksheet from within the UDF
> but you could use a Worksheet_Change event. It will only set the font when
> you enter or change the formula and there is nothing to prevent the user
> changing the format of the cell later.
>
> Not sure of your expertise with VBA but just in case you need help. Right
> click the worksheet tab and select View code and the VBA editor will openat
> the worksheets code. Copy the code and paste into the worksheets code area.
>
> Private Sub Worksheet_Change(ByVal Target As Range)
> * If (Left(LCase(Target.Formula), 6)) = "=myfun" Then
> * * Target.Font.Bold = True
> * * Target.Font.ColorIndex = 3 * 'Red font
> * End If
> End Sub
>
> --
> Regards,
>
> OssieMac
>
>
>
> "Subodh" wrote:
> > I have a my custom function say myfun(arguments)
> > I would like that whenever I use this function in any cell of a
> > workbook (sheet)
> > there should be always be the same font lets say Times New Roman, the
> > font size to be 10, font color automatic.
> > I tried to make another sub that will check every time the sub is
> > entered and ensure that the cell is well
> > with the desired font type. But, I could not get through the sub.
> > Any help in this regard will be appreciated.
> > Thanks in advance.
> > .- Hide quoted text -

>
> - Show quoted text -


Thanks
 
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
Cell Function/Font Color HpyTrvlr69 Microsoft Excel Worksheet Functions 2 12th May 2010 11:08 PM
function that returns cell and or font color of another cell Mark Kubicki Microsoft Excel Programming 2 30th May 2008 03:31 PM
Changing Font color automatically when Cell Format is Percentage Teljon Microsoft Excel Worksheet Functions 1 18th May 2008 06:39 AM
Font to change color automatically based on value in cell. =?Utf-8?B?bXR3ZWxzaDcy?= Microsoft Excel Programming 3 23rd Jan 2005 06:41 PM
Can you change font colour automatically for a cell when you type. =?Utf-8?B?ZWFydGhseV9hbmdlbA==?= Microsoft Excel Worksheet Functions 3 25th Aug 2004 04:12 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:06 AM.