View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.excel.worksheet.functions
papou[_9_] papou[_9_] is offline
external usenet poster
 
Posts: 52
Default Function to return font style

Hi Basil
Public Function TextStyle(Reference As Range)
TextStyle = Range(Reference).Font.FontStyle
End Function

Cordially
Pascal

"Basil" a écrit dans le message de
...
Hi,

I've been looking for a function that will return the style of text within

a cell, but I can't find one!

I am aware that the text within a single cell can actually have multiple

styles, but I am not concerned with this.

So, I tried to create my own function in VBA which nearly works - but I

need help.

The VBA code in my personal module is as follows:

Public Function TextStyle(Reference)
TextStyle = Range(Reference).Font.FontStyle
End Function

The problem as you may have guessed is that Reference will return the

contents of the cell rather than the address (A1 or whatever). A way I
found around this was to change the way I use the function on the worksheet
eg:
=PERSONAL.XLS!TextStyle(ADDRESS(ROW(A1),COLUMN(A1) ,4))

This works, but I would rather just have it so I can say:
=PERSONAL.XLS!TextStyle(A1)

This is the first time I've actually created my own function in Excel, so

any help tips would be really welcomed.

Many thanks,

Basil
PS The function as is would return 0 for cells holding multiple styles