• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Can you format text within a formula?

bobbiejo1104

New Member
I would like to format text within a formula. I have a formula that calculates variances and want to bold and change the color of the text displaying the number if the value of the number is more than $5,000.


My formula is:

="Results indicate that we are "&if(A5<0,"unfavorable","favorable")&" to budget by $"&TEXT(A5,"#,##0")&"."


If the value in A5 is larger than $5,000, I would like to have the $5,000 be displayed in green bold, but leave the rest of the sentence in black.


Thank you!
 
Hi, bobbiejo1104!


First of all welcome to Chandoo's website Excel forums. Thank you for your joining us and glad to have you here.


As a starting point I'd recommend you to read the green sticky topics at this forums main page. There you'll find general guidelines about how this site and community operates (introducing yourself, posting files, netiquette rules, and so on).


Among them you're prompted to perform searches within this site before posting, because maybe your question had been answered yet.


Feel free to play with different keywords so as to be led thru a wide variety of articles and posts, and if you don't find anything that solves your problem or guides you towards a solution, you'll always be welcome back here. Tell us what you've done, consider uploading a sample file as recommended, and somebody surely will read your post and help you.


And about questions in general...


If you haven't performed yet the search herein, try going to the topmost right zone of this page (Custom Search), type the keywords used in Tags field when creating the topic or other proper words and press Search button. You'd retrieve many links from this website, like the following one(s) -if any posted below-, maybe you find useful information and even the solution. If not please advise so as people who read it could get back to you as soon as possible.


And about this question in particular...


Even if formats like this:

[Green][>5000]#,##0;[<=5000]#.##0

can be used for formatting cells, they can't be used in expressions as they apply to the font color attribute of the cell and not to a component of a formula.


You can check that applying that format to cell A5 and changing your TEXT() part of the formula by this:

TEXT(A5,"[Green][>5000]#,##0;[<=5000]#.##0")


General info:

http://office.microsoft.com/en-ca/excel-help/create-a-custom-number-format-HP010342372.aspx


Regards!
 
Unfortunately you can only use one color modifier in a Custom Format


Something like:

[Black][>5000]"Results are greater than budget by "[Green]#,##0;[Black][<=5000]"Results are less than budget by "[Red]#.##0

isn't allowed


Instead of trying to do it all in one cell, I would look at using adjacent cells to do what you want,
 
Hi, bobbiejo1104!


First of all welcome to Chandoo's website Excel forums.


In somehow.. it can be achievable by VBA.. in case if you want to go with VBA..

and need to check data(i your case A5) was inputted by manually then..


Right Click on the SheetName(in which sheet you want to apply color format & Check data) and select View Code

in the blank area.. just paste the below code..

[pre]
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A$5" Then
[a1] = _
"Results indicate that we are " & _
IIf(Target.Value > 0, "Favorable", "UnFavrble") & _
" to budget by " & Format(Target.Value, "$ #,##0") & "."

With [a1].Characters(Start:=53, Length:=Len(Format(Target.Value, "$ #,##0"))).Font
If Target.Value > 5000 Then
.Color = RGB(0, 0, 255)
.FontStyle = "Bold"
Else
.Color = RGB(0, 0, 0)
.FontStyle = "Regular"
End If
End With
End If
End Sub
[/pre]

Please let us know.. if it works for you..


Regards,

Deb
 
Back
Top