Solved

User Defined Function to format text Red in an Excel Formula

Posted on 2014-01-16
6
358 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:CyHill
6 Comments
 
LVL 19

Expert Comment

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

Accepted Solution

by:
Rgonzo1971 earned 500 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:CyHill
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 49

Expert Comment

by:Rgonzo1971
ID: 39794718
Hi,

Unfortunately a function (formula) cannot have different Colors

Regards
0
 

Author Comment

by:CyHill
ID: 39794729
okay...thanks!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

911 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now