Solved

User Defined Function to format text Red in an Excel Formula

Posted on 2014-01-16
6
340 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
Comment Utility
Isn't Excel "Conditional Formatting" enough to get that done?
0
 
LVL 48

Accepted Solution

by:
Rgonzo1971 earned 500 total points
Comment Utility
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
Comment Utility
To make things simple, consider splitting the text into two cells.
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Author Comment

by:CyHill
Comment Utility
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 48

Expert Comment

by:Rgonzo1971
Comment Utility
Hi,

Unfortunately a function (formula) cannot have different Colors

Regards
0
 

Author Comment

by:CyHill
Comment Utility
okay...thanks!
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

What is a Form List Box? (skip if you know this) The forms List Box is the alternative to the ActiveX list box. If you are using excel 2007, you first make sure you have a developer tab (click the Orb)->"Excel Options"->Popular->"Show Developer tab…
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

762 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

13 Experts available now in Live!

Get 1:1 Help Now