View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.misc
Ron Rosenfeld Ron Rosenfeld is offline
external usenet poster
 
Posts: 5,651
Default Formula Text String: Formatting Text and Numbers?

On Fri, 29 Jun 2007 13:28:04 -0700, dj479794
wrote:

Excel 2003

If I havea text string formula and I insert a number. How do I get the
number to be formated with the comma
for "thousands"
[A1]
= "I want to purchase " &C2& " candy bars from the grocery store"

= "I want to purchase " 10,000 " candy bars from the grocery store"

I tried TEXT(A1,#,###) and doesnt work
Also, I want to put only a couple of words in bold font?. For example the
word "purchase".


If the number of candy bars is in C2, then:

A1:
= "I want to purchase " &TEXT(C2,"#,###")
& " candy bars from the grocery store"

will format the value as you describe.

However to bold the word purchase, you will need to use a macro that will place
a text string into A1, rather than a formula. You cannot, in Excel, bold part
of a formula result.

Here's one way:

Right click on the sheet tab.
Select "View Code"
Paste the following into the window that appears.

Type some number into C2.

You will need to modify this to your specific requirements.

=========================================
Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
Const s1 As String = "I want to purchase "
Const s2 As String = " candy bars from the grocery store."
Const sFmt As String = "#,###"
Const sTextToBold As String = "purchase"

With Range("A1")
.Value = s1 & Format(Range("c2"), sFmt) & s2
.Characters(InStr(1, Range("a1").Text, sTextToBold),
Len(sTextToBold)).Font.Bold = True
End With

End Sub
========================================
--ron