Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Format Text During Function

I have a function that transposes names.

Let's say for example that it is:

Smith Jr., James

It works fine but I would like to format (Make Bold and REd) the text in the
resultant cell if it meets a particular condition. I cannot figure out why
this does not work. The function works fine and returns the correct results
but does not format the text if the condition is met.

Any help appreciated...

- - - - - - - - - -- - - - - -
Public Function TransName(MyText) As String

Dim LName, FName As String
Dim Comma, Legnth, JrSuff As Byte

Length = Len(MyText)
Comma = InStr(1, MyText, ",")
Length = Length - Comma

JrSuff = InStr(1, MyText, "Jr")
'Debug.Print JrSuff

LName = Left(MyText, Comma - 1)
FName = Right(MyText, Length)

TransName = FName & " " & LName
TransName = Trim(TransName)

'==== THE FOLLOWING DOES NOT WORK=====

If JrSuff = 1 Then
Selection.Font.ColorIndex = 3
Selection.Font.Bold = True
End If
'========================================
End Function


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Format Text During Function


PJohnson,

"=== THE FOLLOWING DOES NOT WORK====="

because a function can only return a value to the calling cell, and cannot
otherwise change the Excel environment (such as font color or style).

You would need to use a macro or worksheet event to achieve your results.

HTH,
Bernie
MS Excel MVP


"PJohnson" wrote in message
news:5G0oe.27388$iU.19471@lakeread05...
I have a function that transposes names.

Let's say for example that it is:

Smith Jr., James

It works fine but I would like to format (Make Bold and REd) the text in

the
resultant cell if it meets a particular condition. I cannot figure out why
this does not work. The function works fine and returns the correct

results
but does not format the text if the condition is met.

Any help appreciated...

- - - - - - - - - -- - - - - -
Public Function TransName(MyText) As String

Dim LName, FName As String
Dim Comma, Legnth, JrSuff As Byte

Length = Len(MyText)
Comma = InStr(1, MyText, ",")
Length = Length - Comma

JrSuff = InStr(1, MyText, "Jr")
'Debug.Print JrSuff

LName = Left(MyText, Comma - 1)
FName = Right(MyText, Length)

TransName = FName & " " & LName
TransName = Trim(TransName)

'==== THE FOLLOWING DOES NOT WORK=====

If JrSuff = 1 Then
Selection.Font.ColorIndex = 3
Selection.Font.Bold = True
End If
'========================================
End Function




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default Format Text During Function

On Fri, 3 Jun 2005 13:38:11 -0400, "PJohnson" wrote:

I have a function that transposes names.

Let's say for example that it is:

Smith Jr., James

It works fine but I would like to format (Make Bold and REd) the text in the
resultant cell if it meets a particular condition. I cannot figure out why
this does not work. The function works fine and returns the correct results
but does not format the text if the condition is met.

Any help appreciated...


A function can ONLY return a value. It cannot alter properties. (nor can it
call a SUB to do that alteration, a far as I know).

Perhaps you could use conditional formatting to accomplish your goals.


--ron
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
How to format Text by function Edward Wang Excel Worksheet Functions 5 February 13th 09 03:16 AM
using a conditional suffix in text function format syntax=text(value,format_text) Brotherharry Excel Worksheet Functions 1 January 13th 09 03:03 PM
Custo Format for TEXT Function gr8posts Excel Worksheet Functions 5 May 16th 07 04:58 AM
Number format using TEXT( ) function T. Valko Excel Worksheet Functions 6 May 1st 07 05:33 AM
Function to display day in text format Weasel Excel Worksheet Functions 2 February 13th 06 06:47 PM


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