HOW TO FORMATE PART OF TEXT FROM TEXT STRING

V

Vishal

Hi,
Thanks a lot in advance for your help which will help me a lot.

I wanna to bold the part of text from the text string which is in one
cell,this is the string which is joined from different cells into one cell by
using function "CONCATENATE".

Here is the formula to be used
=CONCATENATE("I have ",C42," Rs with me.")
result ;
I have 500 Rs with me.

I wanna to do "500" bold, is there any way for this.

Waiting for the reply,
Regards,
 
R

Rick Rothstein \(MVP - VB\)

You can only format part of the displayed text in a cell differently from
the rest when that text is **not** the result of a formula. You could do
what you want by using an event procedure (which will react to changing the
value in C42). Here is how to do this (if you will need to do this for more
than one cell, you will have to provide more details so the code can be
changed to account for that).

Right-click the tab on the worksheet where you have your current formula and
select View Code from the popup menu that appears. This will take you into
the Visual Basic editor and a code window for that particular worksheet will
already be open (displayed). Simply copy/paste the code below into that open
code window. Next, you have to change the "$A$1" in the FIRST line of the
code to the absolute address (that is, with the dollar signs) of the cell
where you want you text sentence to appear. That is it; you are done. Every
time you change the value in C42, the cell you specified (in place of my
example $A$1 address) will be updated with the number bolded (we can also
change its color, italicize it, underline it, etc. too if you wanted). Now,
when you return to the worksheet, nothing will have happened yet because the
code I gave you only works when C42's value is changed; so, to get things
started, type in a value into C42 (or, if C42 contains a formula, change one
of that formula's dependent cells so the value in C42 is forced to change)
and look at what is displayed in the cell you specified.

'********** START OF CODE **********
Private Sub Worksheet_Change(ByVal Target As Range)

Const CellWithText As String = "$A$1"

If Target.Address = "$C$42" Then
On Error GoTo Whoops
Application.EnableEvents = False
With Range(CellWithText)
.Value = "I have " & Target.Value & " Rs with me."
.Cells.Characters(8, Len(Target.Value)).Font.Bold = True
End With
End If

Whoops:
Application.EnableEvents = True
End Sub
'********** END OF CODE **********


Rick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top