Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

User Defined Function to format text Red in an Excel Formula

Posted on 2014-01-16
6
Medium Priority
?
489 Views
Last Modified: 2014-01-20
Hello -

I'm looking for a way to format certain text within a formula to output as red.

For example, I have a heading with a date and title on the same line.  

January 2013 ~ Report Title

The heading above would be created using a formula, and I can't get the Report Title text to format with red text.

The text would always be the same ("Report Title"), the formula is only needed because the date in the report changes.  

How would you recomend this be done?  What would a user defined function look like for this?  I tried to play with some VB for this, but it's not working and I'm sure I'm way off track on what would be needed fro this.

An example of the current formula would be: =TEXT(TODAY(),"mmmm yyyy")&" ~ Report Title"
0
Comment
Question by:Cynthia Hill
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 20

Expert Comment

by:strivoli
ID: 39787841
Isn't Excel "Conditional Formatting" enough to get that done?
0
 
LVL 53

Accepted Solution

by:
Rgonzo1971 earned 1500 total points
ID: 39787852
Hi,

As far as I know yu cannot change the colour of part of a formula

but you can use VBA

to insert a Report Title like you want

Sub Macro7()
'
' Macro7 Macro
'

'
    ActiveCell.Value = Format(Date, "mmmm yyyy" & " ~ Report Title")
    Set myStr = ActiveCell.Characters()
    myStart = InStrRev(myStr.Text, " ", Len(myStr.Text) - 6) + 1
    myLength = Len(ActiveCell.Value) - myStart + 1
    With ActiveCell.Characters(Start:=myStart, Length:=myLength).Font
        .Color = -16776961
        .TintAndShade = 0
    End With


    With ActiveCell.Characters(Start:=1, Length:=myStart - 1).Font
        .Color = 0
        .TintAndShade = 0
    End With
   
End Sub

Open in new window

Regards
0
 
LVL 43

Expert Comment

by:Saqib Husain, Syed
ID: 39787940
To make things simple, consider splitting the text into two cells.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Cynthia Hill
ID: 39794647
Rgonzo1971 - Thanks for yoru help.

This is a great start to what I was looking for!

It works...I can modify it to make it work for what I need using the Worksheet_Activate function if needed.  

However, I just wanted to check and see if there was a way to improve upon it just a bit.  

Instead of having the function insert the title into the Active Cell...is there a way the code can be set up so I can use an excel formula to reference the title created from the VB code.  

So assign a function name to what the code is doing to create the title itself (for example if we were to name the new function "FormattedTitle"....in any cell within a whorksheet I can just type the formula "=FormattedTitle" and it would populate the title as formated in the code.  

Does that make sense?
0
 
LVL 53

Expert Comment

by:Rgonzo1971
ID: 39794718
Hi,

Unfortunately a function (formula) cannot have different Colors

Regards
0
 

Author Comment

by:Cynthia Hill
ID: 39794729
okay...thanks!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question