Solved

User Defined Function to format text Red in an Excel Formula

Posted on 2014-01-16
6
373 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
ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

 

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

770 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