Solved

User Defined Function to format text Red in an Excel Formula

Posted on 2014-01-16
6
436 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
[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 19

Expert Comment

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

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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 

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 52

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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

This article describes a serious pitfall that can happen when deleting shapes using VBA.
After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.
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…

615 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