Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 99
Default Automatically control the font of a cell when a function is used

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.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default Automatically control the font of a cell when a function is used

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.
.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 99
Default Automatically control the font of a cell when a function is used

On May 7, 1:04*am, OssieMac
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 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.
.- Hide quoted text -


- Show quoted text -


Thanks
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
Cell Function/Font Color HpyTrvlr69 Excel Worksheet Functions 2 May 12th 10 11:08 PM
2007 Form Control/ActiveX Control font difference Nikko963 Excel Discussion (Misc queries) 0 April 15th 09 04:21 PM
function that returns cell and or font color of another cell Mark Kubicki[_2_] Excel Programming 2 May 30th 08 03:31 PM
Changing Font color automatically when Cell Format is Percentage Teljon Excel Worksheet Functions 1 May 18th 08 06:39 AM
Font to change color automatically based on value in cell. mtwelsh72 Excel Programming 3 January 23rd 05 06:41 PM


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